File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Expand file tree Collapse file tree 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:
9292 Takes the "global ID" created by to_global_id, and returns the type name and ID
9393 used to create it.
9494 """
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 ))
9699
97100
98101def global_id_field (
Original file line number Diff line number Diff line change @@ -202,3 +202,15 @@ def allows_to_refetch_the_ids(schema):
202202 },
203203 None ,
204204 )
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