Repository: graphql/graphql-js
Pull request #3729 (2022-09-07 20:12:15)

incrementalDelivery: fix iterable streaming with errors
When iterables (not asyncIterables) are streamed, and completeValue throws an error, we currently send undefined rather than null, due to a typo.

This change corrects the typo, and also modifies the test intended to check this case to correctly check a streamed iterable, rather than an asyncIterable.

Code coverage was complete prior to this change, because the line involving this change was reached in the case where the error was non-recoverable, albeit with the line throwing.

netlify[bot]: ### <span aria-hidden="true">👷</span> Deploy Preview for *compassionate-pike-271cb3* processing.


|  Name | Link |
|---------------------------------|------------------------|
|<span aria-hidden="true">🔨</span> Latest commit | 018aa205f2328e7621078b3dcc67aabb6aea7b0c |
|<span aria-hidden="true">🔍</span> Latest deploy log | https://app.netlify.com/sites/compassionate-pike-271cb3/deploys/6318fb21b3b3900008eb69e3 |
github-actions[bot]: Hi @yaacovCR, I'm @github-actions bot happy to help you with this PR 👋

<details>
<summary> Supported commands </summary>

Please post this commands in separate comments and only one per comment:
* `@github-actions run-benchmark` - Run benchmark comparing base and merge commits for this PR
* `@github-actions publish-pr-on-npm` - Build package from this PR and publish it on NPM
</details>


Patch:
diff --git a/src/execution/execute.ts b/src/execution/execute.ts
index c1f025eb..37eed9e1 100644
--- a/src/execution/execute.ts
+++ b/src/execution/execute.ts
@@ -1838,7 +1838,6 @@ function executeStreamField(
     exeContext,
   });
   let completedItem: PromiseOrValue<unknown>;
-  let completedItems: PromiseOrValue<Array<unknown> | null>;
   try {
     try {
       if (isPromise(item)) {
@@ -1885,7 +1884,7 @@ function executeStreamField(
       }
     } catch (rawError) {
       const error = locatedError(rawError, fieldNodes, pathToArray(itemPath));
-      completedItems = handleFieldError(
+      completedItem = handleFieldError(
         error,
         itemType,
         asyncPayloadRecord.errors,
@@ -1899,6 +1898,7 @@ function executeStreamField(
     return asyncPayloadRecord;
   }
 
+  let completedItems: PromiseOrValue<Array<unknown> | null>;
   if (isPromise(completedItem)) {
     completedItems = completedItem.then(
       (value) => [value],


Test patch:
diff --git a/src/execution/__tests__/stream-test.ts b/src/execution/__tests__/stream-test.ts
index df25d6e8..8378d320 100644
--- a/src/execution/__tests__/stream-test.ts
+++ b/src/execution/__tests__/stream-test.ts
@@ -823,10 +823,7 @@ describe('Execute: stream directive', () => {
       }
     `);
     const result = await complete(document, {
-      async *scalarList() {
-        yield await Promise.resolve(friends[0].name);
-        yield await Promise.resolve({});
-      },
+      scalarList: () => [friends[0].name, {}],
     });
     expectJSON(result).toDeepEqual([
       {
@@ -849,9 +846,6 @@ describe('Execute: stream directive', () => {
             ],
           },
         ],
-        hasNext: true,
-      },
-      {
         hasNext: false,
       },
     ]);