Skip to content

Commit 18d974b

Browse files
committed
Improve coverage for lexicographic_sort_schema
Replicates graphql/graphql-js@784e71b
1 parent 68a735a commit 18d974b

File tree

5 files changed

+21
-18
lines changed

5 files changed

+21
-18
lines changed

graphql/execution/execute.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ def complete_value(
785785
)
786786

787787
# Not reachable. All possible output types have been considered.
788-
raise TypeError(
788+
raise TypeError( # pragma: no cover
789789
f"Cannot complete value of unexpected type '{inspect(return_type)}'."
790790
)
791791

graphql/utilities/build_ast_schema.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,9 @@ def build_type(self, ast_node: TypeDefinitionNode) -> GraphQLNamedType:
280280
}.get(ast_node.kind)
281281
if not method:
282282
# Not reachable. All possible type definition nodes have been considered.
283-
raise TypeError(f"Type kind '{ast_node.kind}' not supported.")
283+
raise TypeError( # pragma: no cover
284+
f"Type kind '{ast_node.kind}' not supported."
285+
)
284286
return method(ast_node) # type: ignore
285287

286288
def _make_type_def(self, ast_node: ObjectTypeDefinitionNode) -> GraphQLObjectType:

graphql/utilities/extend_schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def extend_named_type(type_: GraphQLNamedType) -> GraphQLNamedType:
163163
type_ = cast(GraphQLInputObjectType, type_)
164164
return extend_input_object_type(type_)
165165
# Not reachable. All possible types have been considered.
166-
raise TypeError(f"Type {type_} not supported.")
166+
raise TypeError(f"Type {type_} not supported.") # pragma: no cover
167167

168168
def extend_directive(directive: GraphQLDirective) -> GraphQLDirective:
169169
kwargs = directive.to_kwargs()

graphql/utilities/lexicographic_sort_schema.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ def sort_named_type(type_: GraphQLNamedType) -> GraphQLNamedType:
129129
input_object_type = cast(GraphQLInputObjectType, type_)
130130
kwargs.update(fields=lambda: sort_input_fields(input_object_type.fields))
131131
return GraphQLInputObjectType(**kwargs)
132-
raise TypeError(f"Unknown type: '{type_}'")
132+
# Not reachable. All possible type definition nodes have been considered.
133+
raise TypeError(f"Unknown type: '{type_}'") # pragma: no cover
133134

134135
type_map: Dict[str, GraphQLNamedType] = {
135136
type_.name: sort_named_type(type_)

tests/utilities/test_lexicographic_sort_schema.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ def sort_fields():
1212
sorted_sdl = sort_sdl(
1313
"""
1414
input Bar {
15-
barB: String
15+
barB: String!
1616
barA: String
17-
barC: String
17+
barC: [String]
1818
}
1919
2020
interface FooInterface {
21-
fooB: String
21+
fooB: String!
2222
fooA: String
23-
fooC: String
23+
fooC: [String]
2424
}
2525
2626
type FooType implements FooInterface {
27-
fooC: String
27+
fooC: [String]
2828
fooA: String
29-
fooB: String
29+
fooB: String!
3030
}
3131
3232
type Query {
@@ -39,20 +39,20 @@ def sort_fields():
3939
"""
4040
input Bar {
4141
barA: String
42-
barB: String
43-
barC: String
42+
barB: String!
43+
barC: [String]
4444
}
4545
4646
interface FooInterface {
4747
fooA: String
48-
fooB: String
49-
fooC: String
48+
fooB: String!
49+
fooC: [String]
5050
}
5151
5252
type FooType implements FooInterface {
5353
fooA: String
54-
fooB: String
55-
fooC: String
54+
fooB: String!
55+
fooC: [String]
5656
}
5757
5858
type Query {
@@ -180,15 +180,15 @@ def sort_field_arguments():
180180
sorted_sdl = sort_sdl(
181181
"""
182182
type Query {
183-
dummy(argB: Int, argA: String, argC: Float): ID
183+
dummy(argB: Int!, argA: String, argC: [Float]): ID
184184
}
185185
"""
186186
)
187187

188188
assert sorted_sdl == dedent(
189189
"""
190190
type Query {
191-
dummy(argA: String, argB: Int, argC: Float): ID
191+
dummy(argA: String, argB: Int!, argC: [Float]): ID
192192
}
193193
"""
194194
)

0 commit comments

Comments
 (0)