1
1
from pytest import mark
2
2
3
- from graphql import graphql , graphql_sync
4
- from graphql .type import (
3
+ from graphql import (
4
+ graphql ,
5
+ graphql_sync ,
6
+ print_schema ,
5
7
GraphQLField ,
6
8
GraphQLFieldMap ,
7
9
GraphQLInputField ,
12
14
13
15
from graphql_relay import mutation_with_client_mutation_id
14
16
17
+ from ..utils import dedent
18
+
15
19
16
20
class Result :
17
21
@@ -30,9 +34,7 @@ async def dummy_resolve_async(_info, inputData=None, clientMutationId=None):
30
34
31
35
32
36
def wrap_in_schema (mutation_fields : GraphQLFieldMap ) -> GraphQLSchema :
33
- query_type = GraphQLObjectType (
34
- "DummyQuery" , fields = {"dummy" : GraphQLField (GraphQLInt )}
35
- )
37
+ query_type = GraphQLObjectType ("Query" , fields = {"dummy" : GraphQLField (GraphQLInt )})
36
38
mutation_type = GraphQLObjectType ("Mutation" , fields = mutation_fields )
37
39
return GraphQLSchema (query_type , mutation_type )
38
40
@@ -172,253 +174,36 @@ def supports_mutations_returning_null():
172
174
None ,
173
175
)
174
176
175
- def describe_introspection ():
176
- simple_mutation = mutation_with_client_mutation_id (
177
- "SimpleMutation" ,
178
- input_fields = {},
179
- output_fields = {"result" : GraphQLField (GraphQLInt )},
180
- mutate_and_get_payload = dummy_resolve ,
181
- )
182
-
183
- simple_mutation_with_description = mutation_with_client_mutation_id (
184
- "SimpleMutationWithDescription" ,
185
- description = "Simple Mutation Description" ,
186
- input_fields = {},
187
- output_fields = {"result" : GraphQLField (GraphQLInt )},
188
- mutate_and_get_payload = dummy_resolve ,
189
- )
190
-
191
- simple_mutation_with_deprecation_reason = mutation_with_client_mutation_id (
192
- "SimpleMutationWithDeprecationReason" ,
177
+ def generates_correct_types ():
178
+ some_mutation = mutation_with_client_mutation_id (
179
+ "SomeMutation" ,
180
+ description = "Some Mutation Description" ,
193
181
input_fields = {},
194
182
output_fields = {"result" : GraphQLField (GraphQLInt )},
195
183
mutate_and_get_payload = dummy_resolve ,
196
184
deprecation_reason = "Just because" ,
197
185
)
198
186
199
- schema = wrap_in_schema (
200
- {
201
- "simpleMutation" : simple_mutation ,
202
- "simpleMutationWithDescription" : simple_mutation_with_description ,
203
- "simpleMutationWithDeprecationReason" : simple_mutation_with_deprecation_reason , # noqa: E501
204
- }
205
- )
206
-
207
- def contains_correct_input ():
208
- source = """
209
- {
210
- __type(name: "SimpleMutationInput") {
211
- name
212
- kind
213
- inputFields {
214
- name
215
- type {
216
- name
217
- kind
218
- }
219
- }
220
- }
221
- }
222
- """
223
- assert graphql_sync (schema , source ) == (
224
- {
225
- "__type" : {
226
- "name" : "SimpleMutationInput" ,
227
- "kind" : "INPUT_OBJECT" ,
228
- "inputFields" : [
229
- {
230
- "name" : "clientMutationId" ,
231
- "type" : {"name" : None , "kind" : "NON_NULL" },
232
- }
233
- ],
234
- }
235
- },
236
- None ,
237
- )
187
+ schema = wrap_in_schema ({"someMutation" : some_mutation })
238
188
239
- def contains_correct_payload ():
240
- source = """
241
- {
242
- __type(name: "SimpleMutationPayload") {
243
- name
244
- kind
245
- fields {
246
- name
247
- type {
248
- name
249
- kind
250
- }
251
- }
252
- }
253
- }
254
- """
255
- assert graphql_sync (schema , source ) == (
256
- {
257
- "__type" : {
258
- "name" : "SimpleMutationPayload" ,
259
- "kind" : "OBJECT" ,
260
- "fields" : [
261
- {
262
- "name" : "result" ,
263
- "type" : {"name" : "Int" , "kind" : "SCALAR" },
264
- },
265
- {
266
- "name" : "clientMutationId" ,
267
- "type" : {"name" : None , "kind" : "NON_NULL" },
268
- },
269
- ],
270
- }
271
- },
272
- None ,
273
- )
189
+ assert print_schema (schema ).rstrip () == dedent (
190
+ '''
191
+ type Query {
192
+ dummy: Int
193
+ }
274
194
275
- def contains_correct_field ():
276
- source = """
277
- {
278
- __schema {
279
- mutationType {
280
- fields {
281
- name
282
- args {
283
- name
284
- type {
285
- name
286
- kind
287
- ofType {
288
- name
289
- kind
290
- }
291
- }
292
- }
293
- type {
294
- name
295
- kind
296
- }
297
- }
298
- }
299
- }
300
- }
301
- """
302
- assert graphql_sync (schema , source ) == (
303
- {
304
- "__schema" : {
305
- "mutationType" : {
306
- "fields" : [
307
- {
308
- "name" : "simpleMutation" ,
309
- "args" : [
310
- {
311
- "name" : "input" ,
312
- "type" : {
313
- "name" : None ,
314
- "kind" : "NON_NULL" ,
315
- "ofType" : {
316
- "name" : "SimpleMutationInput" ,
317
- "kind" : "INPUT_OBJECT" ,
318
- },
319
- },
320
- }
321
- ],
322
- "type" : {
323
- "name" : "SimpleMutationPayload" ,
324
- "kind" : "OBJECT" ,
325
- },
326
- },
327
- {
328
- "name" : "simpleMutationWithDescription" ,
329
- "args" : [
330
- {
331
- "name" : "input" ,
332
- "type" : {
333
- "name" : None ,
334
- "kind" : "NON_NULL" ,
335
- "ofType" : {
336
- "name" : "SimpleMutation"
337
- "WithDescriptionInput" ,
338
- "kind" : "INPUT_OBJECT" ,
339
- },
340
- },
341
- }
342
- ],
343
- "type" : {
344
- "name" : "SimpleMutationWithDescriptionPayload" ,
345
- "kind" : "OBJECT" ,
346
- },
347
- },
348
- ]
349
- }
350
- }
351
- },
352
- None ,
353
- )
195
+ type Mutation {
196
+ """Some Mutation Description"""
197
+ someMutation(input: SomeMutationInput!): SomeMutationPayload @deprecated(reason: "Just because")
198
+ }
354
199
355
- def contains_correct_descriptions ():
356
- source = """
357
- {
358
- __schema {
359
- mutationType {
360
- fields {
361
- name
362
- description
363
- }
364
- }
365
- }
366
- }
367
- """
368
- assert graphql_sync (schema , source ) == (
369
- {
370
- "__schema" : {
371
- "mutationType" : {
372
- "fields" : [
373
- {"name" : "simpleMutation" , "description" : None },
374
- {
375
- "name" : "simpleMutationWithDescription" ,
376
- "description" : "Simple Mutation Description" ,
377
- },
378
- ]
379
- }
380
- }
381
- },
382
- None ,
383
- )
200
+ type SomeMutationPayload {
201
+ result: Int
202
+ clientMutationId: String
203
+ }
384
204
385
- def contains_correct_deprecation_reason ():
386
- source = """
387
- {
388
- __schema {
389
- mutationType {
390
- fields(includeDeprecated: true) {
391
- name
392
- isDeprecated
393
- deprecationReason
394
- }
395
- }
396
- }
397
- }
398
- """
399
- assert graphql_sync (schema , source ) == (
400
- {
401
- "__schema" : {
402
- "mutationType" : {
403
- "fields" : [
404
- {
405
- "name" : "simpleMutation" ,
406
- "isDeprecated" : False ,
407
- "deprecationReason" : None ,
408
- },
409
- {
410
- "name" : "simpleMutationWithDescription" ,
411
- "isDeprecated" : False ,
412
- "deprecationReason" : None ,
413
- },
414
- {
415
- "name" : "simpleMutationWithDeprecationReason" ,
416
- "isDeprecated" : True ,
417
- "deprecationReason" : "Just because" ,
418
- },
419
- ]
420
- }
421
- }
422
- },
423
- None ,
424
- )
205
+ input SomeMutationInput {
206
+ clientMutationId: String
207
+ }
208
+ ''' # noqa: E501
209
+ )
0 commit comments