4
4
GraphQLArgument ,
5
5
GraphQLBoolean ,
6
6
GraphQLEnumType ,
7
- GraphQLEnumValue ,
8
7
GraphQLField ,
9
8
GraphQLInputObjectType ,
10
9
GraphQLInt ,
@@ -117,19 +116,13 @@ def prints_object_field():
117
116
name = "Foo" , fields = {"str" : GraphQLField (GraphQLString )}
118
117
)
119
118
120
- query = GraphQLObjectType (name = "Query" , fields = {"foo" : GraphQLField (foo_type )})
121
-
122
- schema = GraphQLSchema (query = query )
119
+ schema = GraphQLSchema (types = [foo_type ])
123
120
output = print_for_test (schema )
124
121
assert output == dedent (
125
122
"""
126
123
type Foo {
127
124
str: String
128
125
}
129
-
130
- type Query {
131
- foo: Foo
132
- }
133
126
"""
134
127
)
135
128
@@ -317,9 +310,7 @@ def prints_interface():
317
310
interfaces = [foo_type ],
318
311
)
319
312
320
- query = GraphQLObjectType (name = "Query" , fields = {"bar" : GraphQLField (bar_type )})
321
-
322
- schema = GraphQLSchema (query , types = [bar_type ])
313
+ schema = GraphQLSchema (types = [bar_type ])
323
314
output = print_for_test (schema )
324
315
assert output == dedent (
325
316
"""
@@ -330,10 +321,6 @@ def prints_interface():
330
321
interface Foo {
331
322
str: String
332
323
}
333
-
334
- type Query {
335
- bar: Bar
336
- }
337
324
"""
338
325
)
339
326
@@ -355,9 +342,7 @@ def prints_multiple_interfaces():
355
342
interfaces = [foo_type , baaz_type ],
356
343
)
357
344
358
- query = GraphQLObjectType (name = "Query" , fields = {"bar" : GraphQLField (bar_type )})
359
-
360
- schema = GraphQLSchema (query , types = [bar_type ])
345
+ schema = GraphQLSchema (types = [bar_type ])
361
346
output = print_for_test (schema )
362
347
assert output == dedent (
363
348
"""
@@ -373,10 +358,6 @@ def prints_multiple_interfaces():
373
358
interface Foo {
374
359
str: String
375
360
}
376
-
377
- type Query {
378
- bar: Bar
379
- }
380
361
"""
381
362
)
382
363
@@ -395,15 +376,7 @@ def prints_unions():
395
376
name = "MultipleUnion" , types = [foo_type , bar_type ]
396
377
)
397
378
398
- query = GraphQLObjectType (
399
- name = "Query" ,
400
- fields = {
401
- "single" : GraphQLField (single_union ),
402
- "multiple" : GraphQLField (multiple_union ),
403
- },
404
- )
405
-
406
- schema = GraphQLSchema (query )
379
+ schema = GraphQLSchema (types = [single_union , multiple_union ])
407
380
output = print_for_test (schema )
408
381
assert output == dedent (
409
382
"""
@@ -417,11 +390,6 @@ def prints_unions():
417
390
418
391
union MultipleUnion = Foo | Bar
419
392
420
- type Query {
421
- single: SingleUnion
422
- multiple: MultipleUnion
423
- }
424
-
425
393
union SingleUnion = Foo
426
394
"""
427
395
)
@@ -431,70 +399,36 @@ def prints_input_type():
431
399
name = "InputType" , fields = {"int" : GraphQLInputField (GraphQLInt )}
432
400
)
433
401
434
- query = GraphQLObjectType (
435
- name = "Query" ,
436
- fields = {
437
- "str" : GraphQLField (
438
- GraphQLString , args = {"argOne" : GraphQLArgument (input_type )}
439
- )
440
- },
441
- )
442
-
443
- schema = GraphQLSchema (query )
402
+ schema = GraphQLSchema (types = [input_type ])
444
403
output = print_for_test (schema )
445
404
assert output == dedent (
446
405
"""
447
406
input InputType {
448
407
int: Int
449
408
}
450
-
451
- type Query {
452
- str(argOne: InputType): String
453
- }
454
409
"""
455
410
)
456
411
457
412
def prints_custom_scalar ():
458
- def serialize (value ):
459
- assert isinstance (value , int )
460
- return value if value % 2 else None
461
-
462
- odd_type = GraphQLScalarType (name = "Odd" , serialize = serialize )
463
-
464
- query = GraphQLObjectType (name = "Query" , fields = {"odd" : GraphQLField (odd_type )})
413
+ odd_type = GraphQLScalarType (name = "Odd" , serialize = lambda : None )
465
414
466
- schema = GraphQLSchema (query )
415
+ schema = GraphQLSchema (types = [ odd_type ] )
467
416
output = print_for_test (schema )
468
417
assert output == dedent (
469
418
"""
470
419
scalar Odd
471
-
472
- type Query {
473
- odd: Odd
474
- }
475
420
"""
476
421
)
477
422
478
423
def prints_enum ():
479
424
rgb_type = GraphQLEnumType (
480
- name = "RGB" ,
481
- values = {
482
- "RED" : GraphQLEnumValue (0 ),
483
- "GREEN" : GraphQLEnumValue (1 ),
484
- "BLUE" : GraphQLEnumValue (2 ),
485
- },
425
+ name = "RGB" , values = dict .fromkeys (("RED" , "GREEN" , "BLUE" ))
486
426
)
487
427
488
- query = GraphQLObjectType (name = "Query" , fields = {"rgb" : GraphQLField (rgb_type )})
489
-
490
- schema = GraphQLSchema (query )
428
+ schema = GraphQLSchema (types = [rgb_type ])
491
429
output = print_for_test (schema )
492
430
assert output == dedent (
493
431
"""
494
- type Query {
495
- rgb: RGB
496
- }
497
-
498
432
enum RGB {
499
433
RED
500
434
GREEN
@@ -504,23 +438,15 @@ def prints_enum():
504
438
)
505
439
506
440
def prints_custom_directives ():
507
- query = GraphQLObjectType (
508
- name = "Query" , fields = {"field" : GraphQLField (GraphQLString )}
509
- )
510
-
511
441
custom_directive = GraphQLDirective (
512
442
name = "customDirective" , locations = [DirectiveLocation .FIELD ]
513
443
)
514
444
515
- schema = GraphQLSchema (query = query , directives = [custom_directive ])
445
+ schema = GraphQLSchema (directives = [custom_directive ])
516
446
output = print_for_test (schema )
517
447
assert output == dedent (
518
448
"""
519
449
directive @customDirective on FIELD
520
-
521
- type Query {
522
- field: String
523
- }
524
450
"""
525
451
)
526
452
@@ -582,11 +508,7 @@ def preserves_leading_spaces_when_printing_a_description():
582
508
assert recreated_field .description == description
583
509
584
510
def prints_introspection_schema ():
585
- query = GraphQLObjectType (
586
- name = "Query" , fields = {"onlyField" : GraphQLField (GraphQLString )}
587
- )
588
-
589
- schema = GraphQLSchema (query )
511
+ schema = GraphQLSchema ()
590
512
output = print_introspection_schema (schema )
591
513
assert output == dedent (
592
514
'''
0 commit comments