11import asyncio
2- from typing import cast , Awaitable
2+ from typing import cast , Any , Awaitable , Optional
33
44from pytest import raises , mark # type: ignore
55
2020 GraphQLSchema ,
2121 GraphQLScalarType ,
2222 GraphQLString ,
23+ GraphQLUnionType ,
2324 ResponsePath ,
2425)
2526
@@ -302,7 +303,7 @@ def resolve(_obj, info):
302303 field_nodes = [field ],
303304 return_type = GraphQLString ,
304305 parent_type = cast (GraphQLObjectType , schema .query_type ),
305- path = ResponsePath (None , "result" ),
306+ path = ResponsePath (None , "result" , "Test" ),
306307 schema = schema ,
307308 fragments = {},
308309 root_value = root_value ,
@@ -312,6 +313,58 @@ def resolve(_obj, info):
312313 is_awaitable = resolved_infos [0 ].is_awaitable ,
313314 )
314315
316+ def it_populates_path_correctly_with_complex_types ():
317+ path : Optional [ResponsePath ] = None
318+
319+ def resolve (_val , info ):
320+ nonlocal path
321+ path = info .path
322+
323+ def resolve_type (_val , _info , _type ):
324+ return "SomeObject"
325+
326+ some_object = GraphQLObjectType (
327+ "SomeObject" , {"test" : GraphQLField (GraphQLString , resolve = resolve )}
328+ )
329+ some_union = GraphQLUnionType (
330+ "SomeUnion" , [some_object ], resolve_type = resolve_type
331+ )
332+ test_type = GraphQLObjectType (
333+ "SomeQuery" ,
334+ {
335+ "test" : GraphQLField (
336+ GraphQLNonNull (GraphQLList (GraphQLNonNull (some_union )))
337+ )
338+ },
339+ )
340+ schema = GraphQLSchema (test_type )
341+ root_value : Any = {"test" : [{}]}
342+ document = parse (
343+ """
344+ query {
345+ l1: test {
346+ ... on SomeObject {
347+ l2: test
348+ }
349+ }
350+ }
351+ """
352+ )
353+
354+ execute_sync (schema , document , root_value )
355+
356+ assert path is not None
357+ prev , key , typename = path
358+ assert key == "l2"
359+ assert typename == "SomeObject"
360+ prev , key , typename = prev
361+ assert key == 0
362+ assert typename is None
363+ prev , key , typename = prev
364+ assert key == "l1"
365+ assert typename == "SomeQuery"
366+ assert prev is None
367+
315368 def threads_root_value_context_correctly ():
316369 resolved_values = []
317370
0 commit comments