Skip to content

Commit

Permalink
Allow string references in InputTypes. Fixed #157
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed May 19, 2016
1 parent 981a7f6 commit d6740e9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions graphene/core/types/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ class InputField(NamedType, OrderedType):
def __init__(self, type, description=None, default=None,
name=None, _creation_counter=None, required=False):
super(InputField, self).__init__(_creation_counter=_creation_counter)
if isinstance(type, six.string_types):
type = LazyType(type)
if required:
type = NonNull(type)
self.type = type
Expand Down
18 changes: 18 additions & 0 deletions graphene/core/types/tests/test_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,24 @@ class Query(ObjectType):
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 resolver(instance, args, info):
return args.get('first_name')
Expand Down

0 comments on commit d6740e9

Please sign in to comment.