Skip to content

Commit e7f3b01

Browse files
committed
locate async iterator errors to the collection
Replicates graphql/graphql-js@bd558cb
1 parent ddfe2bf commit e7f3b01

File tree

3 files changed

+17
-21
lines changed

3 files changed

+17
-21
lines changed

src/graphql/execution/execute.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,15 +1275,9 @@ async def complete_async_iterator_value(
12751275
except StopAsyncIteration:
12761276
break
12771277
except Exception as raw_error:
1278-
self.handle_field_error(
1279-
raw_error,
1280-
item_type,
1281-
field_group,
1282-
item_path,
1283-
incremental_data_record,
1284-
)
1285-
completed_results.append(None)
1286-
break
1278+
raise located_error(
1279+
raw_error, field_group, path.as_list()
1280+
) from raw_error
12871281
if complete_list_item_value(
12881282
value,
12891283
completed_results,
@@ -1897,27 +1891,28 @@ async def execute_stream_async_iterator_item(
18971891
info: GraphQLResolveInfo,
18981892
item_type: GraphQLOutputType,
18991893
incremental_data_record: StreamItemsRecord,
1894+
path: Path,
19001895
item_path: Path,
19011896
) -> Any:
19021897
"""Execute stream iterator item."""
19031898
if async_iterator in self._canceled_iterators:
19041899
raise StopAsyncIteration
19051900
try:
19061901
item = await anext(async_iterator)
1902+
except StopAsyncIteration as raw_error:
1903+
incremental_data_record.set_is_completed_async_iterator()
1904+
raise StopAsyncIteration from raw_error
1905+
except Exception as raw_error:
1906+
raise located_error(raw_error, field_group, path.as_list()) from raw_error
1907+
try:
19071908
completed_item = self.complete_value(
19081909
item_type, field_group, info, item_path, item, incremental_data_record
19091910
)
1910-
19111911
return (
19121912
await completed_item
19131913
if self.is_awaitable(completed_item)
19141914
else completed_item
19151915
)
1916-
1917-
except StopAsyncIteration as raw_error:
1918-
incremental_data_record.set_is_completed_async_iterator()
1919-
raise StopAsyncIteration from raw_error
1920-
19211916
except Exception as raw_error:
19221917
self.handle_field_error(
19231918
raw_error, item_type, field_group, item_path, incremental_data_record
@@ -1952,6 +1947,7 @@ async def execute_stream_async_iterator(
19521947
info,
19531948
item_type,
19541949
incremental_data_record,
1950+
path,
19551951
item_path,
19561952
)
19571953
except StopAsyncIteration:

tests/execution/test_lists.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ async def list_field():
210210
raise RuntimeError("bad")
211211

212212
assert await _complete(list_field()) == (
213-
{"listField": ["two", "4", None]},
214-
[{"message": "bad", "locations": [(1, 3)], "path": ["listField", 2]}],
213+
{"listField": None},
214+
[{"message": "bad", "locations": [(1, 3)], "path": ["listField"]}],
215215
)
216216

217217
@pytest.mark.asyncio()

tests/execution/test_stream.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -893,10 +893,10 @@ async def friend_list(_info):
893893
{
894894
"message": "bad",
895895
"locations": [{"line": 3, "column": 15}],
896-
"path": ["friendList", 1],
896+
"path": ["friendList"],
897897
}
898898
],
899-
"data": {"friendList": [{"name": "Luke", "id": "1"}, None]},
899+
"data": {"friendList": None},
900900
}
901901

902902
@pytest.mark.asyncio()
@@ -929,13 +929,13 @@ async def friend_list(_info):
929929
{
930930
"incremental": [
931931
{
932-
"items": [None],
932+
"items": None,
933933
"path": ["friendList", 1],
934934
"errors": [
935935
{
936936
"message": "bad",
937937
"locations": [{"line": 3, "column": 15}],
938-
"path": ["friendList", 1],
938+
"path": ["friendList"],
939939
},
940940
],
941941
},

0 commit comments

Comments
 (0)