Added some mutable comments

This commit is contained in:
Syrus Akbary 2016-06-04 18:48:32 -07:00
parent 0f10ae884f
commit ff7bf20f6d
2 changed files with 74 additions and 3 deletions

View File

@ -1,8 +1,10 @@
from graphql import graphql, GraphQLSchema
from graphql.utils.introspection_query import introspection_query
from graphql.utils.schema_printer import print_schema
# from graphql.type.schema import assert_object_implements_interface
from ..utils.get_graphql_type import get_graphql_type
# from collections import defaultdict
class Schema(GraphQLSchema):
@ -15,17 +17,24 @@ class Schema(GraphQLSchema):
mutation = get_graphql_type(mutation)
if subscription:
subscription = get_graphql_type(subscription)
if types:
types = map(get_graphql_type, types)
self.types = types
self._executor = executor
super(Schema, self).__init__(
query=query,
mutation=mutation,
subscription=subscription,
directives=directives,
types=types
types=self.types
)
@property
def types(self):
return map(get_graphql_type, self._types or [])
@types.setter
def types(self, value):
self._types = value
def execute(self, request_string='', root_value=None, variable_values=None,
context_value=None, operation_name=None, executor=None):
return graphql(
@ -52,3 +61,19 @@ class Schema(GraphQLSchema):
def lazy(self, _type):
return lambda: self.get_type(_type)
# def rebuild(self):
# self._possible_type_map = defaultdict(set)
# self._type_map = self._build_type_map(self.types)
# # Keep track of all implementations by interface name.
# self._implementations = defaultdict(list)
# for type in self._type_map.values():
# if isinstance(type, GraphQLObjectType):
# for interface in type.get_interfaces():
# self._implementations[interface.name].append(type)
# # Enforce correct interface implementations.
# for type in self._type_map.values():
# if isinstance(type, GraphQLObjectType):
# for interface in type.get_interfaces():
# assert_object_implements_interface(self, type, interface)

View File

@ -2,8 +2,10 @@ import pytest
from graphql import GraphQLObjectType, GraphQLField, GraphQLString, GraphQLInterfaceType
from ..schema import Schema
from ..objecttype import ObjectType
from ..interface import Interface
from ..scalars import String
from ..field import Field
@ -161,3 +163,47 @@ def test_objecttype_graphene_interface():
assert graphql_type.is_type_of(GrapheneObjectType(), None, None)
fields = graphql_type.get_fields()
assert 'field' in fields
# def test_objecttype_graphene_interface_extended():
# class GrapheneInterface(Interface):
# field = Field(GraphQLString)
# class GrapheneObjectType(ObjectType):
# class Meta:
# interfaces = [GrapheneInterface]
# schema = Schema(query=GrapheneObjectType)
# assert str(schema) == """
# schema {
# query: GrapheneObjectType
# }
# interface GrapheneInterface {
# field: String
# }
# type GrapheneObjectType implements GrapheneInterface {
# field: String
# }
# """.lstrip()
# GrapheneInterface._meta.graphql_type.add_field(Field(String, name='dynamic'))
# # GrapheneObjectType._meta.graphql_type._field_map = None
# assert GrapheneInterface._meta.graphql_type.get_fields().keys() == ['field', 'dynamic']
# assert GrapheneObjectType._meta.graphql_type.get_fields().keys() == ['field', 'dynamic']
# schema.rebuild()
# assert str(schema) == """
# schema {
# query: GrapheneObjectType
# }
# interface GrapheneInterface {
# field: String
# dynamic: String
# }
# type GrapheneObjectType implements GrapheneInterface {
# field: String
# dynamic: String
# }
# """.lstrip()