From ac0de32cbee33584405602ed64b455433a2377f1 Mon Sep 17 00:00:00 2001 From: Yaacov Rydzinski Date: Mon, 22 Mar 2021 12:39:46 -0400 Subject: [PATCH] fix(stream): continue on iterator error values if the iterator errors when attempting to get the next value, we can assume subsequent calls to next will also error, and abort, but if we successfully get the next value, but it ends up triggering an error, we can continue, optimistic that the next value will not do so. --- src/execution/__tests__/lists-test.js | 19 +++++++++++++++++++ src/execution/execute.js | 2 -- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/execution/__tests__/lists-test.js b/src/execution/__tests__/lists-test.js index 5e996efbdfd..34864a5bf09 100644 --- a/src/execution/__tests__/lists-test.js +++ b/src/execution/__tests__/lists-test.js @@ -139,6 +139,25 @@ describe('Execute: Accepts async iterables as list value', () => { }); }); + it('Handles an AsyncGenerator function where an intermediate value triggers an error', async () => { + async function* listField() { + yield await 'two'; + yield await {}; + yield await 4; + } + + expect(await complete({ listField })).to.deep.equal({ + data: { listField: ['two', null, '4'] }, + errors: [ + { + message: 'String cannot represent value: {}', + locations: [{ line: 1, column: 3 }], + path: ['listField', 1], + }, + ], + }); + }); + it('Handles errors from `completeValue` in AsyncIterables', async () => { async function* listField() { yield await 'two'; diff --git a/src/execution/execute.js b/src/execution/execute.js index 193fc2afbc5..5b240456a46 100644 --- a/src/execution/execute.js +++ b/src/execution/execute.js @@ -901,8 +901,6 @@ function completeAsyncIteratorValue( pathToArray(fieldPath), ); handleFieldError(error, itemType, exeContext); - resolve(completedResults); - return; } next(index + 1, completedResults);