11from collections import OrderedDict
2- from functools import wraps
32
43from graphene import signals
54from graphql .core .execution .executor import Executor
@@ -21,7 +20,7 @@ class Schema(object):
2120 _executor = None
2221
2322 def __init__ (self , query = None , mutation = None , name = 'Schema' , executor = None ):
24- self ._internal_types = {}
23+ self ._types_names = {}
2524 self ._types = {}
2625 self .mutation = mutation
2726 self .query = query
@@ -36,7 +35,9 @@ def T(self, object_type):
3635 if not object_type :
3736 return
3837 if object_type not in self ._types :
39- self ._types [object_type ] = object_type .internal_type (self )
38+ internal_type = object_type .internal_type (self )
39+ self ._types [object_type ] = internal_type
40+ self ._types_names [internal_type .name ] = object_type
4041 return self ._types [object_type ]
4142
4243 @property
@@ -72,22 +73,19 @@ def schema(self):
7273 raise Exception ('You have to define a base query type' )
7374 return GraphQLSchema (self , query = self .T (self ._query ), mutation = self .T (self ._mutation ))
7475
75- def associate_internal_type (self , internal_type , object_type ):
76- self ._internal_types [internal_type .name ] = object_type
77-
7876 def register (self , object_type ):
79- self ._internal_types [object_type ._meta .type_name ] = object_type
77+ self ._types_names [object_type ._meta .type_name ] = object_type
8078 return object_type
8179
8280 def get_type (self , type_name ):
8381 self .schema ._build_type_map ()
84- if type_name not in self ._internal_types :
82+ if type_name not in self ._types_names :
8583 raise Exception ('Type %s not found in %r' % (type_name , self ))
86- return self ._internal_types [type_name ]
84+ return self ._types_names [type_name ]
8785
8886 @property
8987 def types (self ):
90- return self ._internal_types
88+ return self ._types_names
9189
9290 def execute (self , request = '' , root = None , vars = None , operation_name = None , ** kwargs ):
9391 root = root or object ()
@@ -102,14 +100,3 @@ def execute(self, request='', root=None, vars=None, operation_name=None, **kwarg
102100
103101 def introspect (self ):
104102 return self .execute (introspection_query ).data
105-
106-
107- def register_internal_type (fun ):
108- @wraps (fun )
109- def wrapper (cls , schema ):
110- internal_type = fun (cls , schema )
111- if isinstance (schema , Schema ):
112- schema .associate_internal_type (internal_type , cls )
113- return internal_type
114-
115- return wrapper
0 commit comments