Skip to content

Commit e5660a3

Browse files
committed
Cleanup unnecessary Query types from print_schema tests
Replicates graphql/graphql-js@34b7ced
1 parent 2508417 commit e5660a3

File tree

1 file changed

+11
-89
lines changed

1 file changed

+11
-89
lines changed

tests/utilities/test_schema_printer.py

Lines changed: 11 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
GraphQLArgument,
55
GraphQLBoolean,
66
GraphQLEnumType,
7-
GraphQLEnumValue,
87
GraphQLField,
98
GraphQLInputObjectType,
109
GraphQLInt,
@@ -117,19 +116,13 @@ def prints_object_field():
117116
name="Foo", fields={"str": GraphQLField(GraphQLString)}
118117
)
119118

120-
query = GraphQLObjectType(name="Query", fields={"foo": GraphQLField(foo_type)})
121-
122-
schema = GraphQLSchema(query=query)
119+
schema = GraphQLSchema(types=[foo_type])
123120
output = print_for_test(schema)
124121
assert output == dedent(
125122
"""
126123
type Foo {
127124
str: String
128125
}
129-
130-
type Query {
131-
foo: Foo
132-
}
133126
"""
134127
)
135128

@@ -317,9 +310,7 @@ def prints_interface():
317310
interfaces=[foo_type],
318311
)
319312

320-
query = GraphQLObjectType(name="Query", fields={"bar": GraphQLField(bar_type)})
321-
322-
schema = GraphQLSchema(query, types=[bar_type])
313+
schema = GraphQLSchema(types=[bar_type])
323314
output = print_for_test(schema)
324315
assert output == dedent(
325316
"""
@@ -330,10 +321,6 @@ def prints_interface():
330321
interface Foo {
331322
str: String
332323
}
333-
334-
type Query {
335-
bar: Bar
336-
}
337324
"""
338325
)
339326

@@ -355,9 +342,7 @@ def prints_multiple_interfaces():
355342
interfaces=[foo_type, baaz_type],
356343
)
357344

358-
query = GraphQLObjectType(name="Query", fields={"bar": GraphQLField(bar_type)})
359-
360-
schema = GraphQLSchema(query, types=[bar_type])
345+
schema = GraphQLSchema(types=[bar_type])
361346
output = print_for_test(schema)
362347
assert output == dedent(
363348
"""
@@ -373,10 +358,6 @@ def prints_multiple_interfaces():
373358
interface Foo {
374359
str: String
375360
}
376-
377-
type Query {
378-
bar: Bar
379-
}
380361
"""
381362
)
382363

@@ -395,15 +376,7 @@ def prints_unions():
395376
name="MultipleUnion", types=[foo_type, bar_type]
396377
)
397378

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])
407380
output = print_for_test(schema)
408381
assert output == dedent(
409382
"""
@@ -417,11 +390,6 @@ def prints_unions():
417390
418391
union MultipleUnion = Foo | Bar
419392
420-
type Query {
421-
single: SingleUnion
422-
multiple: MultipleUnion
423-
}
424-
425393
union SingleUnion = Foo
426394
"""
427395
)
@@ -431,70 +399,36 @@ def prints_input_type():
431399
name="InputType", fields={"int": GraphQLInputField(GraphQLInt)}
432400
)
433401

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])
444403
output = print_for_test(schema)
445404
assert output == dedent(
446405
"""
447406
input InputType {
448407
int: Int
449408
}
450-
451-
type Query {
452-
str(argOne: InputType): String
453-
}
454409
"""
455410
)
456411

457412
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)
465414

466-
schema = GraphQLSchema(query)
415+
schema = GraphQLSchema(types=[odd_type])
467416
output = print_for_test(schema)
468417
assert output == dedent(
469418
"""
470419
scalar Odd
471-
472-
type Query {
473-
odd: Odd
474-
}
475420
"""
476421
)
477422

478423
def prints_enum():
479424
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"))
486426
)
487427

488-
query = GraphQLObjectType(name="Query", fields={"rgb": GraphQLField(rgb_type)})
489-
490-
schema = GraphQLSchema(query)
428+
schema = GraphQLSchema(types=[rgb_type])
491429
output = print_for_test(schema)
492430
assert output == dedent(
493431
"""
494-
type Query {
495-
rgb: RGB
496-
}
497-
498432
enum RGB {
499433
RED
500434
GREEN
@@ -504,23 +438,15 @@ def prints_enum():
504438
)
505439

506440
def prints_custom_directives():
507-
query = GraphQLObjectType(
508-
name="Query", fields={"field": GraphQLField(GraphQLString)}
509-
)
510-
511441
custom_directive = GraphQLDirective(
512442
name="customDirective", locations=[DirectiveLocation.FIELD]
513443
)
514444

515-
schema = GraphQLSchema(query=query, directives=[custom_directive])
445+
schema = GraphQLSchema(directives=[custom_directive])
516446
output = print_for_test(schema)
517447
assert output == dedent(
518448
"""
519449
directive @customDirective on FIELD
520-
521-
type Query {
522-
field: String
523-
}
524450
"""
525451
)
526452

@@ -582,11 +508,7 @@ def preserves_leading_spaces_when_printing_a_description():
582508
assert recreated_field.description == description
583509

584510
def prints_introspection_schema():
585-
query = GraphQLObjectType(
586-
name="Query", fields={"onlyField": GraphQLField(GraphQLString)}
587-
)
588-
589-
schema = GraphQLSchema(query)
511+
schema = GraphQLSchema()
590512
output = print_introspection_schema(schema)
591513
assert output == dedent(
592514
'''

0 commit comments

Comments
 (0)