Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 20 additions & 21 deletions src/execution/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2163,12 +2163,12 @@ function firstSyncStreamItems(
info: GraphQLResolveInfo,
itemType: GraphQLOutputType,
): StreamItemsRecord {
const path = streamRecord.path;
const initialPath = addPath(path, initialIndex, undefined);

const firstStreamItems: StreamItemsRecord = {
return {
streamRecord,
result: Promise.resolve().then(() => {
const path = streamRecord.path;
const initialPath = addPath(path, initialIndex, undefined);

let result = completeStreamItems(
streamRecord,
initialPath,
Expand All @@ -2179,7 +2179,8 @@ function firstSyncStreamItems(
info,
itemType,
);
const results = [result];
const firstStreamItems = { result };
let currentStreamItems = firstStreamItems;
let currentIndex = initialIndex;
let iteration = iterator.next();
let erroredSynchronously = false;
Expand All @@ -2201,31 +2202,29 @@ function firstSyncStreamItems(
info,
itemType,
);
results.push(result);

const nextStreamItems: StreamItemsRecord = { streamRecord, result };
currentStreamItems.result = prependNextStreamItems(
currentStreamItems.result,
nextStreamItems,
);
currentStreamItems = nextStreamItems;

iteration = iterator.next();
}

currentIndex = results.length - 1;
// If a non-reconcilable stream items result was encountered, then the stream terminates in error.
// Otherwise, add a stream terminator.
let currentResult = erroredSynchronously
? results[currentIndex]
: prependNextStreamItems(results[currentIndex], {
streamRecord,
result: { streamRecord },
});

while (currentIndex-- > 0) {
currentResult = prependNextStreamItems(results[currentIndex], {
streamRecord,
result: currentResult,
});
if (!erroredSynchronously) {
currentStreamItems.result = prependNextStreamItems(
currentStreamItems.result,
{ streamRecord, result: { streamRecord } },
);
}

return currentResult;
return firstStreamItems.result;
}),
};
return firstStreamItems;
}

function prependNextStreamItems(
Expand Down