Skip to content

Commit f669718

Browse files
committed
Added tests for nested inputobjecttypes
1 parent 0fc7280 commit f669718

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

graphene/types/tests/test_inputobjecttype.py

+37-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from ..inputobjecttype import InputObjectType
66
from ..objecttype import ObjectType
77
from ..unmountedtype import UnmountedType
8+
from ..scalars import String, Boolean
9+
from ..schema import Schema
810

911

1012
class MyType(object):
@@ -51,7 +53,8 @@ class MyInputObjectType(InputObjectType):
5153
field = MyScalar()
5254
asa = InputField(MyType)
5355

54-
assert list(MyInputObjectType._meta.fields.keys()) == ['b', 'a', 'field', 'asa']
56+
assert list(MyInputObjectType._meta.fields.keys()) == [
57+
'b', 'a', 'field', 'asa']
5558

5659

5760
def test_generate_inputobjecttype_unmountedtype():
@@ -86,7 +89,8 @@ class MyInputObjectType(InputObjectType, MyAbstractType):
8689
field2 = MyScalar(MyType)
8790

8891
assert list(MyInputObjectType._meta.fields.keys()) == ['field1', 'field2']
89-
assert [type(x) for x in MyInputObjectType._meta.fields.values()] == [InputField, InputField]
92+
assert [type(x) for x in MyInputObjectType._meta.fields.values()] == [
93+
InputField, InputField]
9094

9195

9296
def test_generate_inputobjecttype_inherit_abstracttype_reversed():
@@ -97,4 +101,34 @@ class MyInputObjectType(MyAbstractType, InputObjectType):
97101
field2 = MyScalar(MyType)
98102

99103
assert list(MyInputObjectType._meta.fields.keys()) == ['field1', 'field2']
100-
assert [type(x) for x in MyInputObjectType._meta.fields.values()] == [InputField, InputField]
104+
assert [type(x) for x in MyInputObjectType._meta.fields.values()] == [
105+
InputField, InputField]
106+
107+
108+
def test_inputobjecttype_of_input():
109+
class Child(InputObjectType):
110+
first_name = String()
111+
last_name = String()
112+
113+
@property
114+
def full_name(self):
115+
return "{} {}".format(self.first_name, self.last_name)
116+
117+
class Parent(InputObjectType):
118+
child = InputField(Child)
119+
120+
class Query(ObjectType):
121+
is_child = Boolean(parent=Parent())
122+
123+
def resolve_is_child(self, info, parent):
124+
return isinstance(parent.child, Child) and parent.child.full_name == "Peter Griffin"
125+
126+
schema = Schema(query=Query)
127+
result = schema.execute('''query basequery {
128+
isChild(parent: {child: {firstName: "Peter", lastName: "Griffin"}})
129+
}
130+
''')
131+
assert not result.errors
132+
assert result.data == {
133+
'isChild': True
134+
}

0 commit comments

Comments
 (0)