Skip to content

Commit a6c15f3

Browse files
committed
fix: allow async errors to bubble to AsyncIterable list items
Replicates graphql/graphql-js@84797fb
1 parent f7e937c commit a6c15f3

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/graphql/execution/execute.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -1213,8 +1213,23 @@ async def complete_async_iterator_value(
12131213
async_payload_record,
12141214
)
12151215
if is_awaitable(completed_item):
1216+
# noinspection PyShadowingNames
1217+
async def catch_error(
1218+
completed_item: Awaitable[Any], field_path: Path
1219+
) -> Any:
1220+
try:
1221+
return await completed_item
1222+
except Exception as raw_error:
1223+
error = located_error(
1224+
raw_error, field_nodes, field_path.as_list()
1225+
)
1226+
handle_field_error(error, item_type, errors)
1227+
return None
1228+
1229+
append_result(catch_error(completed_item, field_path))
12161230
append_awaitable(index)
1217-
append_result(completed_item)
1231+
else:
1232+
append_result(completed_item)
12181233
except Exception as raw_error:
12191234
append_result(None)
12201235
error = located_error(raw_error, field_nodes, field_path.as_list())

tests/execution/test_lists.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
GraphQLField,
1010
GraphQLFieldResolver,
1111
GraphQLList,
12+
GraphQLNonNull,
1213
GraphQLObjectType,
1314
GraphQLResolveInfo,
1415
GraphQLSchema,
@@ -155,7 +156,11 @@ async def _list_field(
155156
GraphQLList(
156157
GraphQLObjectType(
157158
"ObjectWrapper",
158-
{"index": GraphQLField(GraphQLString, resolve=resolve)},
159+
{
160+
"index": GraphQLField(
161+
GraphQLNonNull(GraphQLString), resolve=resolve
162+
)
163+
},
159164
)
160165
),
161166
resolve=_list_field,
@@ -274,7 +279,7 @@ async def resolve(data: _IndexData, info_: GraphQLResolveInfo) -> int:
274279
return index
275280

276281
assert await _complete_object_lists(resolve) == (
277-
{"listField": [{"index": "0"}, {"index": "1"}, {"index": None}]},
282+
{"listField": [{"index": "0"}, {"index": "1"}, None]},
278283
[
279284
{
280285
"message": "bad",

0 commit comments

Comments
 (0)