1
1
from collections import OrderedDict
2
- from functools import wraps
3
2
4
3
from graphene import signals
5
4
from graphql .core .execution .executor import Executor
@@ -21,7 +20,7 @@ class Schema(object):
21
20
_executor = None
22
21
23
22
def __init__ (self , query = None , mutation = None , name = 'Schema' , executor = None ):
24
- self ._internal_types = {}
23
+ self ._types_names = {}
25
24
self ._types = {}
26
25
self .mutation = mutation
27
26
self .query = query
@@ -36,7 +35,9 @@ def T(self, object_type):
36
35
if not object_type :
37
36
return
38
37
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
40
41
return self ._types [object_type ]
41
42
42
43
@property
@@ -72,22 +73,19 @@ def schema(self):
72
73
raise Exception ('You have to define a base query type' )
73
74
return GraphQLSchema (self , query = self .T (self ._query ), mutation = self .T (self ._mutation ))
74
75
75
- def associate_internal_type (self , internal_type , object_type ):
76
- self ._internal_types [internal_type .name ] = object_type
77
-
78
76
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
80
78
return object_type
81
79
82
80
def get_type (self , type_name ):
83
81
self .schema ._build_type_map ()
84
- if type_name not in self ._internal_types :
82
+ if type_name not in self ._types_names :
85
83
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 ]
87
85
88
86
@property
89
87
def types (self ):
90
- return self ._internal_types
88
+ return self ._types_names
91
89
92
90
def execute (self , request = '' , root = None , vars = None , operation_name = None , ** kwargs ):
93
91
root = root or object ()
@@ -102,14 +100,3 @@ def execute(self, request='', root=None, vars=None, operation_name=None, **kwarg
102
100
103
101
def introspect (self ):
104
102
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