mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-02 20:54:16 +03:00
Added some mutable comments
This commit is contained in:
parent
0f10ae884f
commit
ff7bf20f6d
|
@ -1,8 +1,10 @@
|
||||||
from graphql import graphql, GraphQLSchema
|
from graphql import graphql, GraphQLSchema
|
||||||
from graphql.utils.introspection_query import introspection_query
|
from graphql.utils.introspection_query import introspection_query
|
||||||
from graphql.utils.schema_printer import print_schema
|
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 ..utils.get_graphql_type import get_graphql_type
|
||||||
|
# from collections import defaultdict
|
||||||
|
|
||||||
|
|
||||||
class Schema(GraphQLSchema):
|
class Schema(GraphQLSchema):
|
||||||
|
@ -15,17 +17,24 @@ class Schema(GraphQLSchema):
|
||||||
mutation = get_graphql_type(mutation)
|
mutation = get_graphql_type(mutation)
|
||||||
if subscription:
|
if subscription:
|
||||||
subscription = get_graphql_type(subscription)
|
subscription = get_graphql_type(subscription)
|
||||||
if types:
|
self.types = types
|
||||||
types = map(get_graphql_type, types)
|
|
||||||
self._executor = executor
|
self._executor = executor
|
||||||
super(Schema, self).__init__(
|
super(Schema, self).__init__(
|
||||||
query=query,
|
query=query,
|
||||||
mutation=mutation,
|
mutation=mutation,
|
||||||
subscription=subscription,
|
subscription=subscription,
|
||||||
directives=directives,
|
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,
|
def execute(self, request_string='', root_value=None, variable_values=None,
|
||||||
context_value=None, operation_name=None, executor=None):
|
context_value=None, operation_name=None, executor=None):
|
||||||
return graphql(
|
return graphql(
|
||||||
|
@ -52,3 +61,19 @@ class Schema(GraphQLSchema):
|
||||||
|
|
||||||
def lazy(self, _type):
|
def lazy(self, _type):
|
||||||
return lambda: self.get_type(_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)
|
||||||
|
|
|
@ -2,8 +2,10 @@ import pytest
|
||||||
|
|
||||||
from graphql import GraphQLObjectType, GraphQLField, GraphQLString, GraphQLInterfaceType
|
from graphql import GraphQLObjectType, GraphQLField, GraphQLString, GraphQLInterfaceType
|
||||||
|
|
||||||
|
from ..schema import Schema
|
||||||
from ..objecttype import ObjectType
|
from ..objecttype import ObjectType
|
||||||
from ..interface import Interface
|
from ..interface import Interface
|
||||||
|
from ..scalars import String
|
||||||
from ..field import Field
|
from ..field import Field
|
||||||
|
|
||||||
|
|
||||||
|
@ -161,3 +163,47 @@ def test_objecttype_graphene_interface():
|
||||||
assert graphql_type.is_type_of(GrapheneObjectType(), None, None)
|
assert graphql_type.is_type_of(GrapheneObjectType(), None, None)
|
||||||
fields = graphql_type.get_fields()
|
fields = graphql_type.get_fields()
|
||||||
assert 'field' in 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()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user