Skip to content

Commit 027e8f6

Browse files
committed
Simplify SDLs used in build_schema/extend_schema tests
Replicates graphql/graphql-js@24fa31a
1 parent ba36f74 commit 027e8f6

File tree

2 files changed

+20
-85
lines changed

2 files changed

+20
-85
lines changed

tests/utilities/test_build_ast_schema.py

Lines changed: 11 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,7 @@ def simple_type():
121121
assert schema.get_type("ID") is GraphQLID
122122

123123
def include_standard_type_only_if_it_is_used():
124-
schema = build_schema(
125-
"""
126-
type Query {
127-
str: String
128-
}
129-
"""
130-
)
124+
schema = build_schema("type Query")
131125

132126
# Only String and Boolean are used by introspection types
133127
assert schema.get_type("Int") is None
@@ -140,10 +134,6 @@ def with_directives():
140134
sdl = dedent(
141135
"""
142136
directive @foo(arg: Int) on FIELD
143-
144-
type Query {
145-
str: String
146-
}
147137
"""
148138
)
149139
assert cycle_sdl(sdl) == sdl
@@ -176,13 +166,7 @@ def supports_descriptions():
176166
assert cycle_sdl(sdl) == sdl
177167

178168
def maintains_skip_and_include_directives():
179-
schema = build_schema(
180-
"""
181-
type Query {
182-
str: String
183-
}
184-
"""
185-
)
169+
schema = build_schema("type Query")
186170

187171
assert len(schema.directives) == 3
188172
assert schema.get_directive("skip") is GraphQLSkipDirective
@@ -195,10 +179,6 @@ def overriding_directives_excludes_specified():
195179
directive @skip on FIELD
196180
directive @include on FIELD
197181
directive @deprecated on FIELD_DEFINITION
198-
199-
type Query {
200-
str: String
201-
}
202182
"""
203183
)
204184

@@ -215,10 +195,6 @@ def adding_directives_maintains_skip_and_include_directives():
215195
schema = build_schema(
216196
"""
217197
directive @foo(arg: Int) on FIELD
218-
219-
type Query {
220-
str: String
221-
}
222198
"""
223199
)
224200

@@ -256,10 +232,6 @@ def recursive_type():
256232
def two_types_circular():
257233
sdl = dedent(
258234
"""
259-
schema {
260-
query: TypeOne
261-
}
262-
263235
type TypeOne {
264236
str: String
265237
typeTwo: TypeTwo
@@ -816,17 +788,17 @@ def correctly_assign_ast_nodes():
816788
)
817789
assert print_ast_node(test_directive.args["arg"]) == "arg: TestScalar"
818790

819-
def root_operation_type_with_custom_names():
791+
def root_operation_types_with_custom_names():
820792
schema = build_schema(
821793
"""
822794
schema {
823795
query: SomeQuery
824796
mutation: SomeMutation
825797
subscription: SomeSubscription
826798
}
827-
type SomeQuery { str: String }
828-
type SomeMutation { str: String }
829-
type SomeSubscription { str: String }
799+
type SomeQuery
800+
type SomeMutation
801+
type SomeSubscription
830802
"""
831803
)
832804

@@ -837,9 +809,9 @@ def root_operation_type_with_custom_names():
837809
def default_root_operation_type_names():
838810
schema = build_schema(
839811
"""
840-
type Query { str: String }
841-
type Mutation { str: String }
842-
type Subscription { str: String }
812+
type Query
813+
type Mutation
814+
type Subscription
843815
"""
844816
)
845817

@@ -848,14 +820,8 @@ def default_root_operation_type_names():
848820
assert schema.subscription_type.name == "Subscription"
849821

850822
def can_build_invalid_schema():
851-
schema = build_schema(
852-
"""
853-
# Invalid schema, because it is missing query root type
854-
type Mutation {
855-
str: String
856-
}
857-
"""
858-
)
823+
# Invalid schema, because it is missing query root type
824+
schema = build_schema("type Mutation")
859825
errors = validate_schema(schema)
860826
assert errors
861827

tests/utilities/test_extend_schema.py

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,7 @@ def extends_objects_by_adding_new_fields():
222222
assert query_type.fields["foo"].type == foo_type
223223

224224
def extends_objects_with_standard_type_fields():
225-
schema = build_schema(
226-
"""
227-
type Query {
228-
str: String
229-
}
230-
"""
231-
)
225+
schema = build_schema("type Query")
232226

233227
# Only String and Boolean are used by introspection types
234228
assert schema.get_type("Int") is None
@@ -1131,13 +1125,7 @@ def does_not_allow_replacing_an_existing_enum_value():
11311125

11321126
def describe_can_add_additional_root_operation_types():
11331127
def does_not_automatically_include_common_root_type_names():
1134-
schema = extend_test_schema(
1135-
"""
1136-
type Mutation {
1137-
doSomething: String
1138-
}
1139-
"""
1140-
)
1128+
schema = extend_test_schema("type Mutation")
11411129
assert schema.mutation_type is None
11421130

11431131
def adds_schema_definition_missing_in_the_original_schema():
@@ -1163,9 +1151,7 @@ def adds_new_root_types_via_schema_extension():
11631151
mutation: Mutation
11641152
}
11651153
1166-
type Mutation {
1167-
doSomething: String
1168-
}
1154+
type Mutation
11691155
"""
11701156
)
11711157
mutation_type = schema.mutation_type
@@ -1179,13 +1165,8 @@ def adds_multiple_new_root_types_via_schema_extension():
11791165
subscription: Subscription
11801166
}
11811167
1182-
type Mutation {
1183-
doSomething: String
1184-
}
1185-
1186-
type Subscription {
1187-
hearSomething: String
1188-
}
1168+
type Mutation
1169+
type Subscription
11891170
"""
11901171
)
11911172
mutation_type = schema.mutation_type
@@ -1199,18 +1180,12 @@ def applies_multiple_schema_extensions():
11991180
extend schema {
12001181
mutation: Mutation
12011182
}
1183+
type Mutation
12021184
12031185
extend schema {
12041186
subscription: Subscription
12051187
}
1206-
1207-
type Mutation {
1208-
doSomething: String
1209-
}
1210-
1211-
type Subscription {
1212-
hearSomething: String
1213-
}
1188+
type Subscription
12141189
"""
12151190
)
12161191
mutation_type = schema.mutation_type
@@ -1224,18 +1199,12 @@ def schema_extension_ast_are_available_from_schema_object():
12241199
extend schema {
12251200
mutation: Mutation
12261201
}
1202+
type Mutation
12271203
12281204
extend schema {
12291205
subscription: Subscription
12301206
}
1231-
1232-
type Mutation {
1233-
doSomething: String
1234-
}
1235-
1236-
type Subscription {
1237-
hearSomething: String
1238-
}
1207+
type Subscription
12391208
"""
12401209
)
12411210

0 commit comments

Comments
 (0)