5
5
from ..inputobjecttype import InputObjectType
6
6
from ..objecttype import ObjectType
7
7
from ..unmountedtype import UnmountedType
8
+ from ..scalars import String , Boolean
9
+ from ..schema import Schema
8
10
9
11
10
12
class MyType (object ):
@@ -51,7 +53,8 @@ class MyInputObjectType(InputObjectType):
51
53
field = MyScalar ()
52
54
asa = InputField (MyType )
53
55
54
- assert list (MyInputObjectType ._meta .fields .keys ()) == ['b' , 'a' , 'field' , 'asa' ]
56
+ assert list (MyInputObjectType ._meta .fields .keys ()) == [
57
+ 'b' , 'a' , 'field' , 'asa' ]
55
58
56
59
57
60
def test_generate_inputobjecttype_unmountedtype ():
@@ -86,7 +89,8 @@ class MyInputObjectType(InputObjectType, MyAbstractType):
86
89
field2 = MyScalar (MyType )
87
90
88
91
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 ]
90
94
91
95
92
96
def test_generate_inputobjecttype_inherit_abstracttype_reversed ():
@@ -97,4 +101,34 @@ class MyInputObjectType(MyAbstractType, InputObjectType):
97
101
field2 = MyScalar (MyType )
98
102
99
103
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