Skip to content

Commit 5ac32f2

Browse files
committed
build_client_schema: improve coverage
Also fix an incompatibility with GraphQL.js. Replicates graphql/graphql-js@7eb38ea
1 parent d31624b commit 5ac32f2

File tree

5 files changed

+45
-6
lines changed

5 files changed

+45
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ a query language for APIs created by Facebook.
1313
[![Code Style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
1414

1515
The current version 1.0.5 of GraphQL-core-next is up-to-date with GraphQL.js version
16-
14.3.1. All parts of the API are covered by an extensive test suite of currently 1823
16+
14.3.1. All parts of the API are covered by an extensive test suite of currently 1825
1717
unit tests.
1818

1919

graphql/type/directives.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, Optional, Sequence, cast
1+
from typing import Any, Dict, List, Optional, Sequence, cast
22

33
from ..language import ast, DirectiveLocation
44
from ..pyutils import inspect, FrozenList
@@ -177,7 +177,7 @@ def assert_directive(directive: Any) -> GraphQLDirective:
177177
)
178178

179179

180-
specified_directives = FrozenList(
180+
specified_directives: List[GraphQLDirective] = FrozenList(
181181
[GraphQLIncludeDirective, GraphQLSkipDirective, GraphQLDeprecatedDirective]
182182
)
183183
specified_directives.__doc__ = """The full list of specified directives."""

graphql/type/scalars.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from math import isfinite
2-
from typing import Any
2+
from typing import Any, Dict
33

44
from ..error import INVALID
55
from ..pyutils import inspect, is_finite, is_integer, FrozenDict
@@ -241,7 +241,7 @@ def parse_id_literal(ast, _variables=None):
241241
)
242242

243243

244-
specified_scalar_types = FrozenDict(
244+
specified_scalar_types: Dict[str, GraphQLScalarType] = FrozenDict(
245245
{
246246
type_.name: type_
247247
for type_ in (

graphql/type/schema.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ def __init__(
124124
self.mutation_type = mutation
125125
self.subscription_type = subscription
126126
# Provide specified directives (e.g. @include and @skip) by default
127-
self.directives = list(directives or specified_directives)
127+
self.directives = cast(
128+
List[GraphQLDirective],
129+
specified_directives if directives is None else directives,
130+
)
128131
self.ast_node = ast_node
129132
self.extension_ast_nodes = (
130133
cast(Tuple[ast.SchemaExtensionNode], tuple(extension_ast_nodes))

tests/utilities/test_build_client_schema.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,23 @@ def builds_a_simple_schema():
6363

6464
assert cycle_introspection(sdl) == sdl
6565

66+
def builds_a_schema_without_the_query_type():
67+
sdl = dedent(
68+
"""
69+
type Query {
70+
foo: String
71+
}
72+
"""
73+
)
74+
75+
schema = build_schema(sdl)
76+
introspection = introspection_from_schema(schema)
77+
del introspection["__schema"]["queryType"]
78+
79+
client_schema = build_client_schema(introspection)
80+
assert client_schema.query_type is None
81+
assert print_schema(client_schema) == sdl
82+
6683
def builds_a_simple_schema_with_all_operation_types():
6784
sdl = dedent(
6885
'''
@@ -411,6 +428,25 @@ def builds_a_schema_with_custom_directives():
411428

412429
assert cycle_introspection(sdl) == sdl
413430

431+
def builds_a_schema_without_directives():
432+
sdl = dedent(
433+
"""
434+
type Query {
435+
foo: String
436+
}
437+
"""
438+
)
439+
440+
schema = build_schema(sdl)
441+
introspection = introspection_from_schema(schema)
442+
del introspection["__schema"]["directives"]
443+
444+
client_schema = build_client_schema(introspection)
445+
446+
assert schema.directives
447+
assert client_schema.directives == []
448+
assert print_schema(client_schema) == sdl
449+
414450
def builds_a_schema_aware_of_deprecation():
415451
sdl = dedent(
416452
'''

0 commit comments

Comments
 (0)