Skip to content
Closed
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
4 changes: 2 additions & 2 deletions src/graphql_relay/node/node.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Callable, NamedTuple
from typing import Any, Callable, NamedTuple, Union

from graphql_relay.utils.base64 import base64, unbase64

Expand Down Expand Up @@ -78,7 +78,7 @@ class ResolvedGlobalId(NamedTuple):
id: str


def to_global_id(type_: str, id_: str) -> str:
def to_global_id(type_: any, id_: Union[str, int]) -> str:
"""
Takes a type name and an ID specific to that type name, and returns a
"global ID" that is unique among all types.
Expand Down
4 changes: 4 additions & 0 deletions tests/node/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,10 @@ def to_global_id_converts_unicode_strings_correctly():
g_id = to_global_id("MyType", my_unicode_id)
assert g_id == "TXlUeXBlOtut"

def converts_to_global_id():
assert to_global_id("User", 1) == to_global_id("User", "1")
assert to_global_id("User", 1) == to_global_id(user_type, 1)

def from_global_id_converts_unicode_strings_correctly():
my_unicode_id = "ûñö"
my_type, my_id = from_global_id("TXlUeXBlOsO7w7HDtg==")
Expand Down