@@ -1717,11 +1717,13 @@ def first_sync_stream_items(
1717
1717
item_type : GraphQLOutputType ,
1718
1718
) -> StreamItemsRecord :
1719
1719
"""Get the first sync stream items."""
1720
- is_awaitable = self .is_awaitable
1721
- path = stream_record .path
1722
- initial_path = Path (path , initial_index , None )
1723
1720
1724
1721
async def await_result () -> StreamItemsResult :
1722
+ is_awaitable = self .is_awaitable
1723
+ prepend_next_stream_items = self .prepend_next_stream_items
1724
+ path = stream_record .path
1725
+ initial_path = Path (path , initial_index , None )
1726
+
1725
1727
result = self .complete_stream_items (
1726
1728
stream_record ,
1727
1729
initial_path ,
@@ -1731,8 +1733,8 @@ async def await_result() -> StreamItemsResult:
1731
1733
info ,
1732
1734
item_type ,
1733
1735
)
1734
- results = [ result ]
1735
- append_result = results . append
1736
+ first_stream_items = StreamItemsRecord ( stream_record , result )
1737
+ current_stream_items = first_stream_items
1736
1738
current_index = initial_index
1737
1739
errored_synchronously = False
1738
1740
for item in iterator :
@@ -1752,33 +1754,27 @@ async def await_result() -> StreamItemsResult:
1752
1754
info ,
1753
1755
item_type ,
1754
1756
)
1755
- append_result (result )
1756
1757
1757
- current_index = len (results ) - 1
1758
+ next_stream_items = StreamItemsRecord (stream_record , result )
1759
+ current_stream_items .result = prepend_next_stream_items (
1760
+ current_stream_items .result , next_stream_items
1761
+ )
1762
+ current_stream_items = next_stream_items
1763
+
1758
1764
# If a non-reconcilable stream items result was encountered,
1759
1765
# then the stream terminates in error. Otherwise, add a stream terminator.
1760
- prepend_next_stream_items = self .prepend_next_stream_items
1761
- current_result = (
1762
- results [current_index ]
1763
- if errored_synchronously
1764
- else prepend_next_stream_items (
1765
- results [current_index ],
1766
+ if not errored_synchronously :
1767
+ current_stream_items .result = prepend_next_stream_items (
1768
+ current_stream_items .result ,
1766
1769
StreamItemsRecord (
1767
1770
stream_record , TerminatingStreamItemsResult (stream_record )
1768
1771
),
1769
1772
)
1770
- )
1771
1773
1772
- while current_index > 0 :
1773
- current_index -= 1
1774
- current_result = prepend_next_stream_items (
1775
- results [current_index ],
1776
- StreamItemsRecord (stream_record , current_result ),
1777
- )
1778
-
1779
- if is_awaitable (current_result ):
1780
- return await current_result # type: ignore
1781
- return current_result # type: ignore
1774
+ result = first_stream_items .result
1775
+ if is_awaitable (result ):
1776
+ return await result # type: ignore
1777
+ return result # type: ignore
1782
1778
1783
1779
return StreamItemsRecord (stream_record , await_result ())
1784
1780
0 commit comments