Skip to content

Commit a7f3b77

Browse files
committed
Simplified schema code
1 parent b6df2d8 commit a7f3b77

File tree

2 files changed

+8
-24
lines changed

2 files changed

+8
-24
lines changed

graphene/core/schema.py

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from collections import OrderedDict
2-
from functools import wraps
32

43
from graphene import signals
54
from 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

graphene/core/types.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
from graphene import signals
99
from graphene.core.options import Options
10-
from graphene.core.schema import register_internal_type
1110
from graphql.core.type import (GraphQLArgument, GraphQLInputObjectType,
1211
GraphQLInterfaceType, GraphQLObjectType)
1312

@@ -185,7 +184,6 @@ def resolve_type(cls, schema, instance, *args):
185184
return schema.T(objecttype)
186185

187186
@classmethod
188-
@register_internal_type
189187
def internal_type(cls, schema):
190188
fields = lambda: OrderedDict([(f.name, f.internal_field(schema))
191189
for f in cls._meta.fields])
@@ -223,7 +221,6 @@ def get_input_type(cls):
223221
class InputObjectType(ObjectType):
224222

225223
@classmethod
226-
@register_internal_type
227224
def internal_type(cls, schema):
228225
fields = lambda: OrderedDict([(f.name, f.internal_field(schema))
229226
for f in cls._meta.fields])

0 commit comments

Comments
 (0)