Skip to content

Commit d6740e9

Browse files
committed
Allow string references in InputTypes. Fixed #157
1 parent 981a7f6 commit d6740e9

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

graphene/core/types/field.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ class InputField(NamedType, OrderedType):
152152
def __init__(self, type, description=None, default=None,
153153
name=None, _creation_counter=None, required=False):
154154
super(InputField, self).__init__(_creation_counter=_creation_counter)
155+
if isinstance(type, six.string_types):
156+
type = LazyType(type)
155157
if required:
156158
type = NonNull(type)
157159
self.type = type

graphene/core/types/tests/test_field.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,24 @@ class Query(ObjectType):
131131
assert type.default_value == '3'
132132

133133

134+
def test_inputfield_string_reference():
135+
class MyInput(InputObjectType):
136+
my_field = InputField(String, description='My input field', default='3')
137+
138+
my_input_field = InputField('MyInput')
139+
class OtherInput(InputObjectType):
140+
my_input = my_input_field
141+
142+
class Query(ObjectType):
143+
a = String()
144+
145+
schema = Schema(query=Query)
146+
147+
my_input_type = schema.T(MyInput)
148+
my_input_field_type = schema.T(my_input_field)
149+
assert my_input_field_type.type == my_input_type
150+
151+
134152
def test_field_resolve_argument():
135153
def resolver(instance, args, info):
136154
return args.get('first_name')

0 commit comments

Comments
 (0)