Skip to content

Commit 2ed3a7b

Browse files
committed
Unify rest of error messages
Replicates graphql/graphql-js@10b8e95
1 parent 15f8463 commit 2ed3a7b

25 files changed

+237
-201
lines changed

docs/usage/validator.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ As a result, you will get a complete list of all errors that the validators has
2424
In this case, we will get::
2525

2626
[GraphQLError(
27-
'Expected type String!, found NEWHOPE.',
27+
"Expected value of type 'String!', found NEWHOPE.",
2828
locations=[SourceLocation(line=3, column=17)]),
2929
GraphQLError(
3030
"Cannot query field 'homeTown' on type 'Human'."

src/graphql/validation/rules/executable_definitions.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ def enter_document(self, node: DocumentNode, *_args):
2929
if isinstance(
3030
definition, (SchemaDefinitionNode, SchemaExtensionNode)
3131
)
32-
else cast(
33-
Union[DirectiveDefinitionNode, TypeDefinitionNode], definition,
34-
).name.value
32+
else "'{}'".format(
33+
cast(
34+
Union[DirectiveDefinitionNode, TypeDefinitionNode],
35+
definition,
36+
).name.value
37+
)
3538
)
3639
self.report_error(
3740
GraphQLError(

src/graphql/validation/rules/known_argument_names.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ def enter_argument(self, arg_node: ArgumentNode, *args):
7777
suggestions = suggestion_list(arg_name, known_args_names)
7878
context.report_error(
7979
GraphQLError(
80-
f"Unknown argument '{arg_name}' on field '{field_name}'"
81-
f" of type '{parent_type.name}'."
80+
f"Unknown argument '{arg_name}'"
81+
f" on field '{parent_type.name}.{field_name}'."
8282
+ did_you_mean([f"'{s}'" for s in suggestions]),
8383
arg_node,
8484
)

src/graphql/validation/rules/known_directives.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ def enter_directive(self, node: DirectiveNode, _key, _parent, _path, ancestors):
4949
if candidate_location and candidate_location not in locations:
5050
self.report_error(
5151
GraphQLError(
52-
f"Directive '{name}'"
52+
f"Directive '@{name}'"
5353
f" may not be used on {candidate_location.value}.",
5454
node,
5555
)
5656
)
5757
else:
58-
self.report_error(GraphQLError(f"Unknown directive '{name}'.", node))
58+
self.report_error(GraphQLError(f"Unknown directive '@{name}'.", node))
5959

6060

6161
_operation_location = {

src/graphql/validation/rules/no_fragment_cycles.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ def detect_cycle_recursive(self, fragment: FragmentDefinitionNode):
5858
self.detect_cycle_recursive(spread_fragment)
5959
else:
6060
cycle_path = spread_path[cycle_index:]
61-
via_names = [s.name.value for s in cycle_path[:-1]]
61+
via_path = ", ".join("'" + s.name.value + "'" for s in cycle_path[:-1])
6262
self.report_error(
6363
GraphQLError(
6464
f"Cannot spread fragment '{spread_name}' within itself"
65-
+ (f" via {', '.join(via_names)}." if via_names else "."),
65+
+ (f" via {via_path}." if via_path else "."),
6666
cycle_path,
6767
)
6868
)

src/graphql/validation/rules/overlapping_fields_can_be_merged.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ def find_conflict(
545545
name2 = node2.name.value
546546
if name1 != name2:
547547
return (
548-
(response_name, f"{name1} and {name2} are different fields"),
548+
(response_name, f"'{name1}' and '{name2}' are different fields"),
549549
[node1],
550550
[node2],
551551
)
@@ -556,7 +556,7 @@ def find_conflict(
556556

557557
if type1 and type2 and do_types_conflict(type1, type2):
558558
return (
559-
(response_name, f"they return conflicting types {type1} and {type2}"),
559+
(response_name, f"they return conflicting types '{type1}' and '{type2}'"),
560560
[node1],
561561
[node2],
562562
)

src/graphql/validation/rules/possible_type_extensions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def check_extension(self, node: TypeExtensionNode, *_args):
4949

5050
if expected_kind:
5151
if expected_kind != node.kind:
52-
kind_str = extension_kind_to_type_name(expected_kind)
52+
kind_str = extension_kind_to_type_name(node.kind)
5353
self.report_error(
5454
GraphQLError(
5555
f"Cannot extend non-{kind_str} type '{type_name}'.",

src/graphql/validation/rules/unique_directive_names.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def enter_directive_definition(self, node: DirectiveDefinitionNode, *_args):
2424
if self.schema and self.schema.get_directive(directive_name):
2525
self.report_error(
2626
GraphQLError(
27-
f"Directive '{directive_name}' already exists in the schema."
27+
f"Directive '@{directive_name}' already exists in the schema."
2828
" It cannot be redefined.",
2929
node.name,
3030
)
@@ -33,7 +33,7 @@ def enter_directive_definition(self, node: DirectiveDefinitionNode, *_args):
3333
if directive_name in self.known_directive_names:
3434
self.report_error(
3535
GraphQLError(
36-
f"There can be only one directive named '{directive_name}'.",
36+
f"There can be only one directive named '@{directive_name}'.",
3737
[self.known_directive_names[directive_name], node.name],
3838
)
3939
)

src/graphql/validation/rules/unique_directives_per_location.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def enter(self, node: Node, *_args):
4646
if directive_name in known_directives:
4747
self.report_error(
4848
GraphQLError(
49-
f"The directive '{directive_name}'"
49+
f"The directive '@{directive_name}'"
5050
" can only be used once at this location.",
5151
[known_directives[directive_name], directive],
5252
)

src/graphql/validation/rules/unique_variable_names.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def enter_variable_definition(self, node: VariableDefinitionNode, *_args):
2626
if variable_name in known_variable_names:
2727
self.report_error(
2828
GraphQLError(
29-
f"There can be only one variable named '{variable_name}'.",
29+
f"There can be only one variable named '${variable_name}'.",
3030
[known_variable_names[variable_name], node.variable.name],
3131
)
3232
)

0 commit comments

Comments
 (0)