@@ -25,6 +25,7 @@ class Schema(object):
25
25
26
26
def __init__ (self , query = None , mutation = None , name = 'Schema' , executor = None ):
27
27
self ._internal_types = {}
28
+ self ._types = {}
28
29
self .mutation = mutation
29
30
self .query = query
30
31
self .name = name
@@ -34,14 +35,20 @@ def __init__(self, query=None, mutation=None, name='Schema', executor=None):
34
35
def __repr__ (self ):
35
36
return '<Schema: %s (%s)>' % (str (self .name ), hash (self ))
36
37
38
+ def T (self , object_type ):
39
+ if not object_type :
40
+ return
41
+ if object_type not in self ._types :
42
+ self ._types [object_type ] = object_type .internal_type (self )
43
+ return self ._types [object_type ]
44
+
37
45
@property
38
46
def query (self ):
39
47
return self ._query
40
48
41
49
@query .setter
42
50
def query (self , query ):
43
51
self ._query = query
44
- self ._query_type = query and query .internal_type (self )
45
52
46
53
@property
47
54
def mutation (self ):
@@ -50,7 +57,6 @@ def mutation(self):
50
57
@mutation .setter
51
58
def mutation (self , mutation ):
52
59
self ._mutation = mutation
53
- self ._mutation_type = mutation and mutation .internal_type (self )
54
60
55
61
@property
56
62
def executor (self ):
@@ -62,11 +68,11 @@ def executor(self):
62
68
def executor (self , value ):
63
69
self ._executor = value
64
70
65
- @cached_property
71
+ @property
66
72
def schema (self ):
67
- if not self ._query_type :
73
+ if not self ._query :
68
74
raise Exception ('You have to define a base query type' )
69
- return GraphQLSchema (self , query = self ._query_type , mutation = self ._mutation_type )
75
+ return GraphQLSchema (self , query = self .T ( self . _query ) , mutation = self .T ( self . _mutation ) )
70
76
71
77
def associate_internal_type (self , internal_type , object_type ):
72
78
self ._internal_types [internal_type .name ] = object_type
@@ -76,6 +82,7 @@ def register(self, object_type):
76
82
return object_type
77
83
78
84
def get_type (self , type_name ):
85
+ self .schema ._build_type_map ()
79
86
if type_name not in self ._internal_types :
80
87
raise Exception ('Type %s not found in %r' % (type_name , self ))
81
88
return self ._internal_types [type_name ]
0 commit comments