Skip to content

Commit bd30bbb

Browse files
committed
Fixed field type when parent object type is a inputtype
1 parent 129999d commit bd30bbb

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

graphene/core/fields.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def internal_field(self, schema):
134134
object_type = self.get_object_type(schema)
135135
if object_type and object_type._meta.is_mutation:
136136
assert not self.args, 'Arguments provided for mutations are defined in Input class in Mutation'
137-
args = object_type.input_type.fields_as_arguments(schema)
137+
args = object_type.get_input_type().fields_as_arguments(schema)
138138

139139
internal_type = self.internal_type(schema)
140140
if not internal_type:
@@ -151,11 +151,13 @@ def resolver(*args):
151151
else:
152152
resolver = self.resolve
153153

154-
field_type = GraphQLField
155-
if object_type and issubclass(object_type, InputObjectType):
156-
field_type = GraphQLInputObjectField
154+
if issubclass(self.object_type, InputObjectType):
155+
return GraphQLInputObjectField(
156+
internal_type,
157+
description=description,
158+
)
157159

158-
return field_type(
160+
return GraphQLField(
159161
internal_type,
160162
description=description,
161163
args=args,
@@ -164,7 +166,7 @@ def resolver(*args):
164166

165167
def __str__(self):
166168
""" Return "object_type.name". """
167-
return '%s.%s' % (self.object_type, self.field_name)
169+
return '%s.%s' % (self.object_type.__name__, self.field_name)
168170

169171
def __repr__(self):
170172
"""

graphene/core/types.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def is_interface(cls, parents):
2323
return Interface in parents
2424

2525
def is_mutation(cls, parents):
26-
return Mutation in parents
26+
return issubclass(cls, Mutation)
2727

2828
def __new__(cls, name, bases, attrs):
2929
super_new = super(ObjectTypeMeta, cls).__new__
@@ -218,7 +218,9 @@ class ObjectType(six.with_metaclass(ObjectTypeMeta, BaseObjectType)):
218218

219219

220220
class Mutation(six.with_metaclass(ObjectTypeMeta, BaseObjectType)):
221-
pass
221+
@classmethod
222+
def get_input_type(cls):
223+
return getattr(cls, 'input_type', None)
222224

223225

224226
class InputObjectType(ObjectType):

tests/core/test_fields.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ def resolve_customdoc(self, *args, **kwargs):
3131
def __str__(self):
3232
return "ObjectType"
3333

34-
ot = ObjectType()
35-
36-
ObjectType._meta.contribute_to_class(ObjectType, '_meta')
37-
34+
ot = ObjectType
3835

3936
schema = Schema()
4037

0 commit comments

Comments
 (0)