mirror of
https://github.com/graphql-python/graphene.git
synced 2025-05-10 11:23:40 +03:00
Added custom GraphQLSchema
This commit is contained in:
parent
b0e3b3a3af
commit
855cee2f34
|
@ -12,6 +12,7 @@ from django.db.models.query import QuerySet
|
||||||
from django.db.models.manager import Manager
|
from django.db.models.manager import Manager
|
||||||
|
|
||||||
|
|
||||||
|
@memoize
|
||||||
def get_type_for_model(schema, model):
|
def get_type_for_model(schema, model):
|
||||||
schema = schema
|
schema = schema
|
||||||
types = schema.types.values()
|
types = schema.types.values()
|
||||||
|
@ -32,13 +33,15 @@ def lazy_map(value, func):
|
||||||
|
|
||||||
class DjangoConnectionField(relay.ConnectionField):
|
class DjangoConnectionField(relay.ConnectionField):
|
||||||
def wrap_resolved(self, value, instance, args, info):
|
def wrap_resolved(self, value, instance, args, info):
|
||||||
return lazy_map(value, self.field_type)
|
schema = info.schema.graphene_schema
|
||||||
|
return lazy_map(value, self.get_object_type(schema))
|
||||||
|
|
||||||
|
|
||||||
class LazyListField(ListField):
|
class LazyListField(ListField):
|
||||||
def resolve(self, value, instance, args, info):
|
def resolve(self, instance, args, info):
|
||||||
resolved = super(LazyListField, self).resolve(value, instance, args, info)
|
schema = info.schema.graphene_schema
|
||||||
return lazy_map(resolved, self.field_type)
|
resolved = super(LazyListField, self).resolve(instance, args, info)
|
||||||
|
return lazy_map(resolved, self.get_object_type(schema))
|
||||||
|
|
||||||
|
|
||||||
class ConnectionOrListField(LazyField):
|
class ConnectionOrListField(LazyField):
|
||||||
|
|
|
@ -2,12 +2,18 @@ from functools import wraps
|
||||||
|
|
||||||
from graphql.core import graphql
|
from graphql.core import graphql
|
||||||
from graphql.core.type import (
|
from graphql.core.type import (
|
||||||
GraphQLSchema
|
GraphQLSchema as _GraphQLSchema
|
||||||
)
|
)
|
||||||
from graphene import signals
|
from graphene import signals
|
||||||
from graphene.utils import cached_property
|
from graphene.utils import cached_property
|
||||||
|
|
||||||
|
|
||||||
|
class GraphQLSchema(_GraphQLSchema):
|
||||||
|
def __init__(self, schema, *args, **kwargs):
|
||||||
|
self.graphene_schema = schema
|
||||||
|
super(GraphQLSchema, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class Schema(object):
|
class Schema(object):
|
||||||
_query = None
|
_query = None
|
||||||
|
|
||||||
|
@ -34,7 +40,7 @@ class Schema(object):
|
||||||
def schema(self):
|
def schema(self):
|
||||||
if not self._query_type:
|
if not self._query_type:
|
||||||
raise Exception('You have to define a base query type')
|
raise Exception('You have to define a base query type')
|
||||||
return GraphQLSchema(query=self._query_type, mutation=self.mutation)
|
return GraphQLSchema(self, query=self._query_type, mutation=self.mutation)
|
||||||
|
|
||||||
def associate_internal_type(self, internal_type, object_type):
|
def associate_internal_type(self, internal_type, object_type):
|
||||||
self._internal_types[internal_type.name] = object_type
|
self._internal_types[internal_type.name] = object_type
|
||||||
|
|
Loading…
Reference in New Issue
Block a user