4
4
GraphQLInputObjectType , GraphQLInterfaceType ,
5
5
GraphQLObjectType , GraphQLString )
6
6
7
+ from ..structures import List , NonNull
7
8
from ..dynamic import Dynamic
8
9
from ..enum import Enum
9
10
from ..field import Field
10
11
from ..inputfield import InputField
11
12
from ..inputobjecttype import InputObjectType
12
13
from ..interface import Interface
13
14
from ..objecttype import ObjectType
14
- from ..scalars import String
15
+ from ..scalars import String , Int
15
16
from ..typemap import TypeMap
16
17
17
18
@@ -119,10 +120,18 @@ def resolve_foo(self, args, info):
119
120
120
121
121
122
def test_inputobject ():
123
+ class OtherObjectType (InputObjectType ):
124
+ thingy = NonNull (Int )
125
+
126
+ class MyInnerObjectType (InputObjectType ):
127
+ some_field = String ()
128
+ some_other_field = List (OtherObjectType )
129
+
122
130
class MyInputObjectType (InputObjectType ):
123
131
'''Description'''
124
132
foo_bar = String (description = 'Field description' )
125
133
bar = String (name = 'gizmo' )
134
+ baz = NonNull (MyInnerObjectType )
126
135
own = InputField (lambda : MyInputObjectType )
127
136
128
137
def resolve_foo_bar (self , args , info ):
@@ -136,14 +145,23 @@ def resolve_foo_bar(self, args, info):
136
145
assert graphql_type .description == 'Description'
137
146
138
147
# Container
139
- container = graphql_type .create_container ({'bar' : 'oh!' })
148
+ container = graphql_type .create_container ({
149
+ 'bar' : 'oh!' ,
150
+ 'baz' : {
151
+ 'some_other_field' : [{'thingy' : 1 }, {'thingy' : 2 }]
152
+ }
153
+ })
140
154
assert isinstance (container , MyInputObjectType )
141
155
assert 'bar' in container
142
156
assert container .bar == 'oh!'
143
157
assert 'foo_bar' not in container
158
+ assert container .foo_bar is None
159
+ assert container .baz .some_field is None
160
+ assert container .baz .some_other_field [0 ].thingy == 1
161
+ assert container .baz .some_other_field [1 ].thingy == 2
144
162
145
163
fields = graphql_type .fields
146
- assert list (fields .keys ()) == ['fooBar' , 'gizmo' , 'own' ]
164
+ assert list (fields .keys ()) == ['fooBar' , 'gizmo' , 'baz' , ' own' ]
147
165
own_field = fields ['own' ]
148
166
assert own_field .type == graphql_type
149
167
foo_field = fields ['fooBar' ]
0 commit comments