Skip to content

Commit 881a148

Browse files
committed
is_valid_name_error: Remove node argument
Replicates graphql/graphql-js@d72cd3d
1 parent 5b185f2 commit 881a148

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

src/graphql/error/located_error.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import TYPE_CHECKING, Collection, Union
1+
from typing import TYPE_CHECKING, Collection, Optional, Union
22

33
from .graphql_error import GraphQLError
44

@@ -10,8 +10,8 @@
1010

1111
def located_error(
1212
original_error: Union[Exception, GraphQLError],
13-
nodes: Collection["Node"],
14-
path: Collection[Union[str, int]],
13+
nodes: Optional[Union["None", Collection["Node"]]],
14+
path: Optional[Collection[Union[str, int]]] = None,
1515
) -> GraphQLError:
1616
"""Located GraphQL Error
1717
@@ -26,18 +26,22 @@ def located_error(
2626
if isinstance(original_error, GraphQLError) and original_error.path is not None:
2727
return original_error
2828
try:
29+
# noinspection PyUnresolvedReferences
2930
message = original_error.message # type: ignore
3031
except AttributeError:
3132
message = str(original_error)
3233
try:
34+
# noinspection PyUnresolvedReferences
3335
source = original_error.source # type: ignore
3436
except AttributeError:
3537
source = None
3638
try:
39+
# noinspection PyUnresolvedReferences
3740
positions = original_error.positions # type: ignore
3841
except AttributeError:
3942
positions = None
4043
try:
44+
# noinspection PyUnresolvedReferences
4145
nodes = original_error.nodes or nodes # type: ignore
4246
except AttributeError:
4347
pass

src/graphql/type/validate.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
cast,
1313
)
1414

15-
16-
from ..error import GraphQLError
15+
from ..error import GraphQLError, located_error
1716
from ..pyutils import inspect
1817
from ..language import NamedTypeNode, Node, OperationType, OperationTypeDefinitionNode
1918
from .definition import (
@@ -174,9 +173,9 @@ def validate_name(self, node: Any, name: Optional[str] = None) -> None:
174173
except AttributeError: # pragma: no cover
175174
pass
176175
else:
177-
error = is_valid_name_error(name, ast_node)
176+
error = is_valid_name_error(name)
178177
if error:
179-
self.add_error(error)
178+
self.add_error(located_error(error, ast_node))
180179

181180
def validate_types(self) -> None:
182181
validate_input_object_circular_refs = InputObjectCircularRefsValidator(self)

src/graphql/utilities/assert_valid_name.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import re
22
from typing import Optional
33

4-
from ..language import Node
54
from ..error import GraphQLError
65

76
__all__ = ["assert_valid_name", "is_valid_name_error"]
@@ -18,20 +17,17 @@ def assert_valid_name(name: str) -> str:
1817
return name
1918

2019

21-
def is_valid_name_error(
22-
name: str, node: Optional[Node] = None
23-
) -> Optional[GraphQLError]:
20+
def is_valid_name_error(name: str) -> Optional[GraphQLError]:
2421
"""Return an Error if a name is invalid."""
2522
if not isinstance(name, str):
2623
raise TypeError("Expected name to be a string.")
2724
if name.startswith("__"):
2825
return GraphQLError(
2926
f"Name {name!r} must not begin with '__',"
30-
" which is reserved by GraphQL introspection.",
31-
node,
27+
" which is reserved by GraphQL introspection."
3228
)
3329
if not re_name.match(name):
3430
return GraphQLError(
35-
f"Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but {name!r} does not.", node
31+
f"Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but {name!r} does not."
3632
)
3733
return None

0 commit comments

Comments
 (0)