mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-22 17:46:57 +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
|
||||
|
||||
|
||||
@memoize
|
||||
def get_type_for_model(schema, model):
|
||||
schema = schema
|
||||
types = schema.types.values()
|
||||
|
@ -32,13 +33,15 @@ def lazy_map(value, func):
|
|||
|
||||
class DjangoConnectionField(relay.ConnectionField):
|
||||
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):
|
||||
def resolve(self, value, instance, args, info):
|
||||
resolved = super(LazyListField, self).resolve(value, instance, args, info)
|
||||
return lazy_map(resolved, self.field_type)
|
||||
def resolve(self, instance, args, info):
|
||||
schema = info.schema.graphene_schema
|
||||
resolved = super(LazyListField, self).resolve(instance, args, info)
|
||||
return lazy_map(resolved, self.get_object_type(schema))
|
||||
|
||||
|
||||
class ConnectionOrListField(LazyField):
|
||||
|
|
|
@ -2,12 +2,18 @@ from functools import wraps
|
|||
|
||||
from graphql.core import graphql
|
||||
from graphql.core.type import (
|
||||
GraphQLSchema
|
||||
GraphQLSchema as _GraphQLSchema
|
||||
)
|
||||
from graphene import signals
|
||||
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):
|
||||
_query = None
|
||||
|
||||
|
@ -34,7 +40,7 @@ class Schema(object):
|
|||
def schema(self):
|
||||
if not self._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):
|
||||
self._internal_types[internal_type.name] = object_type
|
||||
|
|
Loading…
Reference in New Issue
Block a user