Skip to content

Commit c6c295f

Browse files
committed
build_client_schema: include standard type only if it is used
Replicates graphql/graphql-js@ff0afa2
1 parent f4af437 commit c6c295f

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

graphql/utilities/build_client_schema.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,8 @@ def build_directive(directive_introspection: Dict) -> GraphQLDirective:
312312
for std_type_name, std_type in chain(
313313
specified_scalar_types.items(), introspection_types.items()
314314
):
315-
type_map[std_type_name] = std_type
315+
if std_type_name in type_map:
316+
type_map[std_type_name] = std_type
316317

317318
# Get the root Query, Mutation, and Subscription types.
318319

tests/utilities/test_build_client_schema.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,12 @@ def cycle_introspection(sdl_string):
3939
# it should get a result identical to what was returned by the server
4040
second_introspection = introspection_from_schema(client_schema)
4141

42-
hack_to_remove_standard_types(second_introspection)
43-
hack_to_remove_standard_types(initial_introspection)
44-
4542
# If the client then runs the introspection query against the client-side
4643
# schema, it should get a result identical to what was returned by the server.
4744
assert initial_introspection == second_introspection
4845
return print_schema(client_schema)
4946

5047

51-
# Temporary hack to remove always presented standard types - should be removed in 15.0
52-
def hack_to_remove_standard_types(introspection):
53-
introspection["__schema"]["types"] = [
54-
type_
55-
for type_ in introspection["__schema"]["types"]
56-
if type_["name"] not in ("ID", "Float", "Int", "Boolean", "String")
57-
]
58-
59-
6048
def describe_type_system_build_schema_from_introspection():
6149
def builds_a_simple_schema():
6250
sdl = dedent(
@@ -139,6 +127,21 @@ def uses_built_in_scalars_when_possible():
139127
custom_scalar = schema.get_type("CustomScalar")
140128
assert client_schema.get_type("CustomScalar") is not custom_scalar
141129

130+
def include_standard_type_only_if_it_is_used():
131+
schema = build_schema(
132+
"""
133+
type Query {
134+
foo: String
135+
}
136+
"""
137+
)
138+
introspection = introspection_from_schema(schema)
139+
client_schema = build_client_schema(introspection)
140+
141+
assert client_schema.get_type("Int") is None
142+
assert client_schema.get_type("Float") is None
143+
assert client_schema.get_type("ID") is None
144+
142145
def builds_a_schema_with_a_recursive_type_reference():
143146
sdl = dedent(
144147
"""
@@ -325,10 +328,8 @@ def builds_a_schema_with_an_enum():
325328

326329
introspection = introspection_from_schema(schema)
327330
client_schema = build_client_schema(introspection)
328-
second_introspection = introspection_from_schema(client_schema)
329331

330-
hack_to_remove_standard_types(second_introspection)
331-
hack_to_remove_standard_types(introspection)
332+
second_introspection = introspection_from_schema(client_schema)
332333
assert second_introspection == introspection
333334

334335
client_food_enum = client_schema.get_type("Food")

0 commit comments

Comments
 (0)