Allow string references in InputTypes. Fixed #157

This commit is contained in:
Syrus Akbary 2016-05-18 21:49:37 -07:00
parent 981a7f665a
commit d6740e9ff5
2 changed files with 20 additions and 0 deletions

View File

@ -152,6 +152,8 @@ class InputField(NamedType, OrderedType):
def __init__(self, type, description=None, default=None, def __init__(self, type, description=None, default=None,
name=None, _creation_counter=None, required=False): name=None, _creation_counter=None, required=False):
super(InputField, self).__init__(_creation_counter=_creation_counter) super(InputField, self).__init__(_creation_counter=_creation_counter)
if isinstance(type, six.string_types):
type = LazyType(type)
if required: if required:
type = NonNull(type) type = NonNull(type)
self.type = type self.type = type

View File

@ -131,6 +131,24 @@ def test_inputfield_internal_type():
assert type.default_value == '3' assert type.default_value == '3'
def test_inputfield_string_reference():
class MyInput(InputObjectType):
my_field = InputField(String, description='My input field', default='3')
my_input_field = InputField('MyInput')
class OtherInput(InputObjectType):
my_input = my_input_field
class Query(ObjectType):
a = String()
schema = Schema(query=Query)
my_input_type = schema.T(MyInput)
my_input_field_type = schema.T(my_input_field)
assert my_input_field_type.type == my_input_type
def test_field_resolve_argument(): def test_field_resolve_argument():
def resolver(instance, args, info): def resolver(instance, args, info):
return args.get('first_name') return args.get('first_name')