Fixed field type when parent object type is a inputtype

This commit is contained in:
Syrus Akbary 2015-10-27 21:49:40 -07:00
parent 129999d41a
commit bd30bbb322
3 changed files with 13 additions and 12 deletions

View File

@ -134,7 +134,7 @@ class Field(object):
object_type = self.get_object_type(schema)
if object_type and object_type._meta.is_mutation:
assert not self.args, 'Arguments provided for mutations are defined in Input class in Mutation'
args = object_type.input_type.fields_as_arguments(schema)
args = object_type.get_input_type().fields_as_arguments(schema)
internal_type = self.internal_type(schema)
if not internal_type:
@ -151,11 +151,13 @@ class Field(object):
else:
resolver = self.resolve
field_type = GraphQLField
if object_type and issubclass(object_type, InputObjectType):
field_type = GraphQLInputObjectField
if issubclass(self.object_type, InputObjectType):
return GraphQLInputObjectField(
internal_type,
description=description,
)
return field_type(
return GraphQLField(
internal_type,
description=description,
args=args,
@ -164,7 +166,7 @@ class Field(object):
def __str__(self):
""" Return "object_type.name". """
return '%s.%s' % (self.object_type, self.field_name)
return '%s.%s' % (self.object_type.__name__, self.field_name)
def __repr__(self):
"""

View File

@ -23,7 +23,7 @@ class ObjectTypeMeta(type):
return Interface in parents
def is_mutation(cls, parents):
return Mutation in parents
return issubclass(cls, Mutation)
def __new__(cls, name, bases, attrs):
super_new = super(ObjectTypeMeta, cls).__new__
@ -218,7 +218,9 @@ class ObjectType(six.with_metaclass(ObjectTypeMeta, BaseObjectType)):
class Mutation(six.with_metaclass(ObjectTypeMeta, BaseObjectType)):
pass
@classmethod
def get_input_type(cls):
return getattr(cls, 'input_type', None)
class InputObjectType(ObjectType):

View File

@ -31,10 +31,7 @@ class ObjectType(object):
def __str__(self):
return "ObjectType"
ot = ObjectType()
ObjectType._meta.contribute_to_class(ObjectType, '_meta')
ot = ObjectType
schema = Schema()