@@ -146,6 +146,56 @@ class QueryRoot(gql.QueryRoot):
146
146
})
147
147
148
148
149
+ def test_field_arguments ():
150
+ gql = Schema ()
151
+
152
+ class A (gql .ObjectType ):
153
+ pass
154
+
155
+ class QueryRoot (gql .QueryRoot ):
156
+ field = gql .Field (gql .String , {
157
+ 'byPublicType' : gql .Argument (A ),
158
+ 'byName' : gql .Argument ('A' ),
159
+ 'byInternalType' : gql .Argument (gql .String ),
160
+ 'byPublicTypeWrapped' : gql .Argument (gql .List (A )),
161
+ 'byNameWrapped' : gql .Argument (gql .List ('A' )),
162
+ 'byInternalTypeWrapped' : gql .Argument (gql .List (gql .String )),
163
+ })
164
+
165
+ result = graphql (gql .to_internal (), '''{
166
+ type: __type(name: "QueryRoot") {
167
+ fields {
168
+ args {
169
+ name
170
+ type { ...TypeRef }
171
+ }
172
+ }
173
+ }
174
+ }
175
+ fragment TypeRef on __Type {
176
+ kind, name
177
+ ofType {
178
+ kind, name
179
+ ofType { kind, name, ofType }
180
+ }
181
+ }''' )
182
+ assert not result .errors
183
+ a_type = {"kind" : "OBJECT" , "name" : "A" , "ofType" : None }
184
+ string_type = {"kind" : "SCALAR" , "name" : "String" , "ofType" : None }
185
+ assert sort_lists (result .data ) == sort_lists ({
186
+ "type" : {
187
+ "fields" : [{"args" : [
188
+ {"name" : "byPublicType" , "type" : a_type },
189
+ {"name" : "byName" , "type" : a_type },
190
+ {"name" : "byInternalType" , "type" : string_type },
191
+ {"name" : "byPublicTypeWrapped" , "type" : {"kind" : "LIST" , "name" : None , "ofType" : a_type }},
192
+ {"name" : "byNameWrapped" , "type" : {"kind" : "LIST" , "name" : None , "ofType" : a_type }},
193
+ {"name" : "byInternalTypeWrapped" , "type" : {"kind" : "LIST" , "name" : None , "ofType" : string_type }},
194
+ ]}]
195
+ }
196
+ })
197
+
198
+
149
199
def test_prevent_defining_many_query_roots ():
150
200
gql = Schema ()
151
201
@@ -155,3 +205,42 @@ class QueryRoot(gql.QueryRoot):
155
205
with raises (Exception ):
156
206
class SecondQueryRoot (gql .QueryRoot ):
157
207
pass
208
+
209
+
210
+ def test_define_union_type ():
211
+ gql = Schema ()
212
+
213
+ class A (gql .ObjectType ):
214
+ pass
215
+
216
+ class B (gql .ObjectType ):
217
+ pass
218
+
219
+ class UnionType (gql .UnionType ):
220
+ """description"""
221
+ __typename__ = 'Union'
222
+ types = [A , B ]
223
+
224
+ class QueryRoot (gql .QueryRoot ):
225
+ union = gql .Field (UnionType )
226
+
227
+ result = graphql (gql .to_internal (), '''{
228
+ type: __type(name: "Union") {
229
+ kind
230
+ name
231
+ description
232
+ possibleTypes { name }
233
+ }
234
+ }''' )
235
+ assert not result .errors
236
+ assert sort_lists (result .data ) == sort_lists ({
237
+ "type" : {
238
+ "name" : "Union" ,
239
+ "description" : "description" ,
240
+ "kind" : "UNION" ,
241
+ "possibleTypes" : [
242
+ {"name" : "A" },
243
+ {"name" : "B" },
244
+ ]
245
+ }
246
+ })
0 commit comments