@@ -2105,25 +2105,39 @@ def default_type_resolver(
21052105 # Otherwise, test each possible type.
21062106 possible_types = info .schema .get_possible_types (abstract_type )
21072107 is_awaitable = info .is_awaitable
2108- awaitable_is_type_of_results : list [Awaitable ] = []
2109- append_awaitable_results = awaitable_is_type_of_results .append
2108+ awaitable_is_type_of_results : list [Awaitable [ bool ] ] = []
2109+ append_awaitable_result = awaitable_is_type_of_results .append
21102110 awaitable_types : list [GraphQLObjectType ] = []
2111- append_awaitable_types = awaitable_types .append
2111+ append_awaitable_type = awaitable_types .append
21122112
21132113 for type_ in possible_types :
21142114 if type_ .is_type_of :
21152115 is_type_of_result = type_ .is_type_of (value , info )
21162116
21172117 if is_awaitable (is_type_of_result ):
2118- append_awaitable_results (cast ("Awaitable" , is_type_of_result ))
2119- append_awaitable_types (type_ )
2118+ append_awaitable_result (cast ("Awaitable[bool] " , is_type_of_result ))
2119+ append_awaitable_type (type_ )
21202120 elif is_type_of_result :
21212121 return type_ .name
21222122
21232123 if awaitable_is_type_of_results :
21242124 # noinspection PyShadowingNames
21252125 async def get_type () -> str | None :
2126- is_type_of_results = await gather (* awaitable_is_type_of_results )
2126+ tasks = [
2127+ create_task (result ) # type: ignore[arg-type]
2128+ for result in awaitable_is_type_of_results
2129+ ]
2130+
2131+ try :
2132+ is_type_of_results = await gather (* tasks )
2133+ except Exception :
2134+ # Cancel unfinished tasks before raising the exception
2135+ for task in tasks :
2136+ if not task .done ():
2137+ task .cancel ()
2138+ await gather (* tasks , return_exceptions = True )
2139+ raise
2140+
21272141 for is_type_of_result , type_ in zip (is_type_of_results , awaitable_types ):
21282142 if is_type_of_result :
21292143 return type_ .name
0 commit comments