Skip to content

Commit 72bf40e

Browse files
committed
build_ast_schema: should match order of default types and directives
Replicates graphql/graphql-js@96c2d06
1 parent 4c14db3 commit 72bf40e

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

src/graphql/utilities/build_ast_schema.py

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
from typing import Union
22

3-
from ..language import (
4-
DocumentNode,
5-
Source,
6-
parse,
7-
)
8-
from ..type import (
9-
GraphQLDeprecatedDirective,
10-
GraphQLIncludeDirective,
11-
GraphQLSchema,
12-
GraphQLSkipDirective,
13-
GraphQLSpecifiedByDirective,
14-
)
3+
from ..language import DocumentNode, Source, parse
4+
from ..type import GraphQLSchema, specified_directives
155
from .extend_schema import extend_schema_impl
166

177
__all__ = [
@@ -74,14 +64,9 @@ def build_ast_schema(
7464

7565
directives = schema_kwargs["directives"]
7666
# If specified directives were not explicitly declared, add them.
77-
if not any(directive.name == "skip" for directive in directives):
78-
directives.append(GraphQLSkipDirective)
79-
if not any(directive.name == "include" for directive in directives):
80-
directives.append(GraphQLIncludeDirective)
81-
if not any(directive.name == "deprecated" for directive in directives):
82-
directives.append(GraphQLDeprecatedDirective)
83-
if not any(directive.name == "specifiedBy" for directive in directives):
84-
directives.append(GraphQLSpecifiedByDirective)
67+
for std_directive in specified_directives:
68+
if all(directive.name != std_directive.name for directive in directives):
69+
directives.append(std_directive)
8570

8671
return GraphQLSchema(**schema_kwargs)
8772

tests/utilities/test_build_ast_schema.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from graphql.type import (
99
GraphQLDeprecatedDirective,
1010
GraphQLIncludeDirective,
11+
GraphQLSchema,
1112
GraphQLSkipDirective,
1213
GraphQLSpecifiedByDirective,
1314
GraphQLBoolean,
@@ -114,6 +115,13 @@ def ignores_non_type_system_definitions():
114115
"""
115116
build_schema(sdl)
116117

118+
def match_order_of_default_types_and_directives():
119+
schema = GraphQLSchema()
120+
sdl_schema = build_ast_schema(DocumentNode(definitions=[]))
121+
122+
assert sdl_schema.directives == schema.directives
123+
assert sdl_schema.type_map == schema.type_map
124+
117125
def empty_type():
118126
sdl = dedent(
119127
"""

0 commit comments

Comments
 (0)