1
- from typing import Any , Callable , NamedTuple , Optional
1
+ from typing import Any , Callable , NamedTuple , Optional , Union
2
2
3
3
from graphql_relay .utils .base64 import base64 , unbase64
4
4
@@ -22,7 +22,7 @@ class GraphQLNodeDefinitions(NamedTuple):
22
22
23
23
24
24
def node_definitions (
25
- id_fetcher : Callable [[str , GraphQLResolveInfo ], Any ],
25
+ fetch_by_id : Callable [[str , GraphQLResolveInfo ], Any ],
26
26
type_resolver : Optional [GraphQLTypeResolver ] = None ,
27
27
) -> GraphQLNodeDefinitions :
28
28
"""
@@ -55,7 +55,7 @@ def node_definitions(
55
55
GraphQLNonNull (GraphQLID ), description = "The ID of an object"
56
56
)
57
57
},
58
- resolve = lambda _obj , info , id : id_fetcher (id , info ),
58
+ resolve = lambda _obj , info , id : fetch_by_id (id , info ),
59
59
)
60
60
61
61
nodes_field = GraphQLField (
@@ -67,7 +67,7 @@ def node_definitions(
67
67
description = "The IDs of objects" ,
68
68
)
69
69
},
70
- resolve = lambda _obj , info , ids : [id_fetcher (id_ , info ) for id_ in ids ],
70
+ resolve = lambda _obj , info , ids : [fetch_by_id (id_ , info ) for id_ in ids ],
71
71
)
72
72
73
73
return GraphQLNodeDefinitions (node_interface , node_field , nodes_field )
@@ -79,12 +79,12 @@ class ResolvedGlobalId(NamedTuple):
79
79
id : str
80
80
81
81
82
- def to_global_id (type_ : str , id_ : str ) -> str :
82
+ def to_global_id (type_ : str , id_ : Union [ str , int ] ) -> str :
83
83
"""
84
84
Takes a type name and an ID specific to that type name, and returns a
85
85
"global ID" that is unique among all types.
86
86
"""
87
- return base64 (f"{ type_ } :{ id_ } " )
87
+ return base64 (f"{ type_ } :{ GraphQLID . serialize ( id_ ) } " )
88
88
89
89
90
90
def from_global_id (global_id : str ) -> ResolvedGlobalId :
0 commit comments