Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/graphql/type/assert_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def assert_name(name: str) -> str:
if not name:
msg = "Expected name to be a non-empty string."
raise GraphQLError(msg)
if name.isascii() and name.isidentifier():
return name # an ASCII identifier is exactly a GraphQL name
if not all(is_name_continue(char) for char in name[1:]):
msg = f"Names must only contain [_a-zA-Z0-9] but {name!r} does not."
raise GraphQLError(msg)
Expand Down
10 changes: 10 additions & 0 deletions tests/type/test_assert_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ def describe_assert_name():
def pass_through_valid_name():
assert assert_name("_ValidName123") == "_ValidName123"

def pass_through_valid_name_without_the_shortcut():
class Name(str):
__slots__ = ()

def isidentifier(self) -> bool:
return False

name = Name("_ValidName123")
assert assert_name(name) is name

def throws_on_empty_strings():
with pytest.raises(GraphQLError) as exc_info:
assert_name("")
Expand Down
Loading