Skip to content

Commit 510dbd3

Browse files
committed
Fix execute_stream_async_iterator
1 parent 76e45ac commit 510dbd3

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

src/graphql/execution/execute.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,6 +1683,7 @@ async def execute_stream_async_iterator(
16831683
index = initial_index
16841684
previous_incremental_data_record = parent_context
16851685

1686+
done = False
16861687
while True:
16871688
item_path = Path(path, index, None)
16881689
incremental_data_record = (
@@ -1692,7 +1693,7 @@ async def execute_stream_async_iterator(
16921693
)
16931694

16941695
try:
1695-
data = await self.execute_stream_async_iterator_item(
1696+
completed_item = await self.execute_stream_async_iterator_item(
16961697
async_iterator,
16971698
field_group,
16981699
info,
@@ -1701,8 +1702,6 @@ async def execute_stream_async_iterator(
17011702
path,
17021703
item_path,
17031704
)
1704-
except StopAsyncIteration:
1705-
break
17061705
except GraphQLError as error:
17071706
incremental_publisher.add_field_error(incremental_data_record, error)
17081707
incremental_publisher.filter(path, incremental_data_record)
@@ -1716,12 +1715,16 @@ async def execute_stream_async_iterator(
17161715
# so we need to remember that this iterator is already canceled
17171716
self._canceled_iterators.add(async_iterator)
17181717
break
1719-
else:
1720-
incremental_publisher.complete_stream_items_record(
1721-
incremental_data_record,
1722-
[data],
1723-
)
1718+
except StopAsyncIteration:
1719+
done = True
1720+
1721+
incremental_publisher.complete_stream_items_record(
1722+
incremental_data_record,
1723+
[completed_item],
1724+
)
17241725

1726+
if done:
1727+
break
17251728
previous_incremental_data_record = incremental_data_record
17261729
index += 1
17271730

tests/execution/test_stream.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,9 @@ async def friend_list(_info):
743743
"path": ["friendList", 2],
744744
}
745745
],
746+
"hasNext": True,
747+
},
748+
{
746749
"hasNext": False,
747750
},
748751
]
@@ -783,6 +786,9 @@ async def friend_list(_info):
783786
"path": ["friendList", 2],
784787
}
785788
],
789+
"hasNext": True,
790+
},
791+
{
786792
"hasNext": False,
787793
},
788794
]
@@ -856,10 +862,10 @@ async def friend_list(_info):
856862
"path": ["friendList", 2],
857863
}
858864
],
859-
"hasNext": False,
865+
"hasNext": True,
860866
},
861867
},
862-
{"done": True, "value": None},
868+
{"done": False, "value": {"hasNext": False}},
863869
{"done": True, "value": None},
864870
]
865871

0 commit comments

Comments
 (0)