Skip to content

Commit

Permalink
Fix execute_stream_async_iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
Cito committed Aug 10, 2024
1 parent 76e45ac commit 642d4cf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
19 changes: 11 additions & 8 deletions src/graphql/execution/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -1683,6 +1683,7 @@ async def execute_stream_async_iterator(
index = initial_index
previous_incremental_data_record = parent_context

done = False
while True:
item_path = Path(path, index, None)
incremental_data_record = (
Expand All @@ -1692,7 +1693,7 @@ async def execute_stream_async_iterator(
)

try:
data = await self.execute_stream_async_iterator_item(
completed_item = await self.execute_stream_async_iterator_item(
async_iterator,
field_group,
info,
Expand All @@ -1701,8 +1702,6 @@ async def execute_stream_async_iterator(
path,
item_path,
)
except StopAsyncIteration:
break
except GraphQLError as error:
incremental_publisher.add_field_error(incremental_data_record, error)
incremental_publisher.filter(path, incremental_data_record)
Expand All @@ -1716,11 +1715,15 @@ async def execute_stream_async_iterator(
# so we need to remember that this iterator is already canceled
self._canceled_iterators.add(async_iterator)
break
else:
incremental_publisher.complete_stream_items_record(
incremental_data_record,
[data],
)
except StopAsyncIteration:
done = True

incremental_publisher.complete_stream_items_record(
incremental_data_record,
[completed_item],
)
if done:
break

previous_incremental_data_record = incremental_data_record
index += 1
Expand Down
10 changes: 8 additions & 2 deletions tests/execution/test_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,9 @@ async def friend_list(_info):
"path": ["friendList", 2],
}
],
"hasNext": True,
},
{
"hasNext": False,
},
]
Expand Down Expand Up @@ -783,6 +786,9 @@ async def friend_list(_info):
"path": ["friendList", 2],
}
],
"hasNext": True,
},
{
"hasNext": False,
},
]
Expand Down Expand Up @@ -856,10 +862,10 @@ async def friend_list(_info):
"path": ["friendList", 2],
}
],
"hasNext": False,
"hasNext": True,
},
},
{"done": True, "value": None},
{"done": False, "value": {"hasNext": False}},
{"done": True, "value": None},
]

Expand Down

0 comments on commit 642d4cf

Please sign in to comment.