File tree 2 files changed +16
-1
lines changed
2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -92,7 +92,10 @@ def from_global_id(global_id: str) -> ResolvedGlobalId:
92
92
Takes the "global ID" created by to_global_id, and returns the type name and ID
93
93
used to create it.
94
94
"""
95
- return ResolvedGlobalId (* unbase64 (global_id ).split (":" , 1 ))
95
+ global_id = unbase64 (global_id )
96
+ if ":" not in global_id :
97
+ return ResolvedGlobalId ("" , global_id )
98
+ return ResolvedGlobalId (* global_id .split (":" , 1 ))
96
99
97
100
98
101
def global_id_field (
Original file line number Diff line number Diff line change @@ -202,3 +202,15 @@ def allows_to_refetch_the_ids(schema):
202
202
},
203
203
None ,
204
204
)
205
+
206
+ def handles_valid_global_ids ():
207
+ assert from_global_id ("Zm9v" ) == ("" , "foo" )
208
+ assert from_global_id (b"Zm9v" ) == ("" , "foo" ) # type: ignore
209
+ assert from_global_id ("Zm9vOmJhcg==" ) == ("foo" , "bar" )
210
+ assert from_global_id (b"Zm9vOmJhcg==" ) == ("foo" , "bar" ) # type: ignore
211
+
212
+ def handles_invalid_global_ids ():
213
+ assert from_global_id ("" ) == ("" , "" )
214
+ assert from_global_id ("Og==" ) == ("" , "" )
215
+ assert from_global_id ("bad!" ) == ("" , "" )
216
+ assert from_global_id ("invalid" ) == ("" , "" )
You can’t perform that action at this time.
0 commit comments