Skip to content

Commit 1d6e008

Browse files
committed
extend_schema: Do not modify standard directives
Replicates graphql/graphql-js@fdc3555
1 parent 2792f59 commit 1d6e008

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/graphql/utilities/extend_schema.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
is_non_null_type,
8181
is_object_type,
8282
is_scalar_type,
83+
is_specified_directive,
8384
is_specified_scalar_type,
8485
is_union_type,
8586
specified_scalar_types,
@@ -257,6 +258,10 @@ def replace_named_type(self, type_: GraphQLNamedType) -> GraphQLNamedType:
257258

258259
# noinspection PyShadowingNames
259260
def replace_directive(self, directive: GraphQLDirective) -> GraphQLDirective:
261+
if is_specified_directive(directive):
262+
# Builtin directives are not extended.
263+
return directive
264+
260265
kwargs = directive.to_kwargs()
261266
return GraphQLDirective(
262267
**merge_kwargs(

tests/utilities/test_extend_schema.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
assert_object_type,
2424
assert_scalar_type,
2525
assert_union_type,
26+
specified_directives,
2627
validate_schema,
2728
)
2829
from graphql.utilities import build_schema, concat_ast, extend_schema, print_schema
@@ -102,6 +103,38 @@ def can_be_used_for_limited_execution():
102103
)
103104
assert result == ({"newField": "123"}, None)
104105

106+
def does_not_modify_built_in_types_and_directives():
107+
schema = build_schema(
108+
"""
109+
type Query {
110+
str: String
111+
int: Int
112+
float: Float
113+
id: ID
114+
bool: Boolean
115+
}
116+
"""
117+
)
118+
119+
extension_sdl = dedent(
120+
"""
121+
extend type Query {
122+
foo: String
123+
}
124+
"""
125+
)
126+
127+
extended_schema = extend_schema(schema, parse(extension_sdl))
128+
129+
# built-ins are used
130+
assert extended_schema.get_type("Int") is GraphQLInt
131+
assert extended_schema.get_type("Float") is GraphQLFloat
132+
assert extended_schema.get_type("String") is GraphQLString
133+
assert extended_schema.get_type("Boolean") is GraphQLBoolean
134+
assert extended_schema.get_type("ID") is GraphQLID
135+
136+
assert extended_schema.directives == specified_directives
137+
105138
def extends_objects_by_adding_new_fields():
106139
schema = build_schema(
107140
'''

0 commit comments

Comments
 (0)