Skip to content

Commit ae2ccea

Browse files
committed
GraphQLError: don't wrap single node in array
Replicates graphql/graphql-js@fbd9c47
1 parent a0a737c commit ae2ccea

22 files changed

+38
-45
lines changed

graphql/execution/values.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def get_variable_values(
5858
f"Variable '${var_name}' expected value of type"
5959
f" '{print_ast(var_def_node.type)}'"
6060
" which cannot be used as an input type.",
61-
[var_def_node.type],
61+
var_def_node.type,
6262
)
6363
)
6464
else:
@@ -79,7 +79,7 @@ def get_variable_values(
7979
if has_value
8080
else f"Variable '${var_name}' of required type"
8181
f" '{var_type}' was not provided.",
82-
[var_def_node],
82+
var_def_node,
8383
)
8484
)
8585
elif has_value:
@@ -146,21 +146,21 @@ def get_argument_values(
146146
raise GraphQLError(
147147
f"Argument '{name}' of non-null type"
148148
f" '{arg_type}' must not be null.",
149-
[argument_node.value],
149+
argument_node.value,
150150
)
151151
elif argument_node and isinstance(argument_node.value, VariableNode):
152152
raise GraphQLError(
153153
f"Argument '{name}' of required type"
154154
f" '{arg_type}' was provided the variable"
155155
f" '${variable_name}'"
156156
" which was not provided a runtime value.",
157-
[argument_node.value],
157+
argument_node.value,
158158
)
159159
else:
160160
raise GraphQLError(
161161
f"Argument '{name}' of required type '{arg_type}'"
162162
" was not provided.",
163-
[node],
163+
node,
164164
)
165165
elif has_value:
166166
if isinstance(argument_node.value, NullValueNode):
@@ -183,7 +183,7 @@ def get_argument_values(
183183
raise GraphQLError(
184184
f"Argument '{name}'"
185185
f" has invalid value {print_ast(value_node)}.",
186-
[argument_node.value],
186+
argument_node.value,
187187
)
188188
coerced_values[name] = coerced_value
189189
return coerced_values

graphql/type/validate.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,7 @@ def report_error(
9393
message: str,
9494
nodes: Union[Optional[Node], Sequence[Optional[Node]]] = None,
9595
):
96-
if isinstance(nodes, Node):
97-
nodes = [nodes]
98-
if nodes:
96+
if nodes and not isinstance(nodes, Node):
9997
nodes = [node for node in nodes if node]
10098
nodes = cast(Optional[Sequence[Node]], nodes)
10199
self.add_error(GraphQLError(message, nodes))

graphql/utilities/find_deprecated_usages.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def enter_field(self, node, *_args):
4242
GraphQLError(
4343
f"The field {parent_type.name}.{field_name}"
4444
" is deprecated." + (f" {reason}" if reason else ""),
45-
[node],
45+
node,
4646
)
4747
)
4848

@@ -57,6 +57,6 @@ def enter_enum_value(self, node, *_args):
5757
GraphQLError(
5858
f"The enum value {type_.name}.{enum_val_name}"
5959
" is deprecated." + (f" {reason}" if reason else ""),
60-
[node],
60+
node,
6161
)
6262
)

graphql/utilities/get_operation_root_type.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,20 @@ def get_operation_root_type(
2121
query_type = schema.query_type
2222
if not query_type:
2323
raise GraphQLError(
24-
"Schema does not define the required query root type.", [operation]
24+
"Schema does not define the required query root type.", operation
2525
)
2626
return query_type
2727
elif operation_type == OperationType.MUTATION:
2828
mutation_type = schema.mutation_type
2929
if not mutation_type:
30-
raise GraphQLError("Schema is not configured for mutations.", [operation])
30+
raise GraphQLError("Schema is not configured for mutations.", operation)
3131
return mutation_type
3232
elif operation_type == OperationType.SUBSCRIPTION:
3333
subscription_type = schema.subscription_type
3434
if not subscription_type:
35-
raise GraphQLError(
36-
"Schema is not configured for subscriptions.", [operation]
37-
)
35+
raise GraphQLError("Schema is not configured for subscriptions.", operation)
3836
return subscription_type
3937
else:
4038
raise GraphQLError(
41-
"Can only have query, mutation and subscription operations.", [operation]
39+
"Can only have query, mutation and subscription operations.", operation
4240
)

graphql/validation/rules/executable_definitions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def enter_document(self, node: DocumentNode, *_args):
4040
definition,
4141
).name.value
4242
),
43-
[definition],
43+
definition,
4444
)
4545
)
4646
return self.SKIP

graphql/validation/rules/fields_on_correct_type.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def enter_field(self, node: FieldNode, *_args):
6363
undefined_field_message(
6464
field_name, type_.name, suggested_type_names, suggested_field_names
6565
),
66-
[node],
66+
node,
6767
)
6868
)
6969

graphql/validation/rules/fragments_on_composite_types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def enter_inline_fragment(self, node: InlineFragmentNode, *_args):
3737
inline_fragment_on_non_composite_error_message(
3838
print_ast(type_condition)
3939
),
40-
[type_condition],
40+
type_condition,
4141
)
4242
)
4343

@@ -50,6 +50,6 @@ def enter_fragment_definition(self, node: FragmentDefinitionNode, *_args):
5050
fragment_on_non_composite_error_message(
5151
node.name.value, print_ast(type_condition)
5252
),
53-
[type_condition],
53+
type_condition,
5454
)
5555
)

graphql/validation/rules/known_directives.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ def enter_directive(self, node: DirectiveNode, _key, _parent, _path, ancestors):
6464
misplaced_directive_message(
6565
node.name.value, candidate_location.value
6666
),
67-
[node],
67+
node,
6868
)
6969
)
7070
else:
7171
self.report_error(
72-
GraphQLError(unknown_directive_message(node.name.value), [node])
72+
GraphQLError(unknown_directive_message(node.name.value), node)
7373
)
7474

7575

graphql/validation/rules/known_fragment_names.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ def enter_fragment_spread(self, node: FragmentSpreadNode, *_args):
2121
fragment = self.context.get_fragment(fragment_name)
2222
if not fragment:
2323
self.report_error(
24-
GraphQLError(unknown_fragment_message(fragment_name), [node.name])
24+
GraphQLError(unknown_fragment_message(fragment_name), node.name)
2525
)

graphql/validation/rules/lone_anonymous_operation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ def enter_document(self, node: DocumentNode, *_args):
3030
def enter_operation_definition(self, node: OperationDefinitionNode, *_args):
3131
if not node.name and self.operation_count > 1:
3232
self.report_error(
33-
GraphQLError(anonymous_operation_not_alone_message(), [node])
33+
GraphQLError(anonymous_operation_not_alone_message(), node)
3434
)

0 commit comments

Comments
 (0)