diff --git a/src/execution/execute.ts b/src/execution/execute.ts index 2df10335591..9644a79f46e 100644 --- a/src/execution/execute.ts +++ b/src/execution/execute.ts @@ -1116,27 +1116,9 @@ async function completeAsyncIteratorValue( break; } - const item = iteration.value; - // TODO: add test case for asyncIterator returning a promise - /* c8 ignore start */ - if (isPromise(item)) { - completedResults.push( - completePromisedListItemValue( - item, - exeContext, - itemType, - fieldGroup, - info, - itemPath, - incrementalContext, - deferMap, - ), - ); - containsPromise = true; - } else if ( - /* c8 ignore stop */ + if ( completeListItemValue( - item, + iteration.value, completedResults, exeContext, itemType, @@ -1229,24 +1211,7 @@ async function completeAsyncIteratorValueWithPossibleStream( } const item = iteration.value; - // TODO: add tests for stream backed by asyncIterator that returns a promise - /* c8 ignore start */ - if (isPromise(item)) { - completedResults.push( - completePromisedListItemValue( - item, - exeContext, - itemType, - fieldGroup, - info, - itemPath, - incrementalContext, - deferMap, - ), - ); - containsPromise = true; - } else if ( - /* c8 ignore stop */ + if ( completeListItemValue( item, completedResults, @@ -1370,21 +1335,7 @@ function completeIterableValue( // since from here on it is not ever accessed by resolver functions. const itemPath = addPath(path, index, undefined); - if (isPromise(item)) { - completedResults.push( - completePromisedListItemValue( - item, - exeContext, - itemType, - fieldGroup, - info, - itemPath, - incrementalContext, - deferMap, - ), - ); - containsPromise = true; - } else if ( + if ( completeListItemValue( item, completedResults, @@ -1461,21 +1412,7 @@ function completeIterableValueWithPossibleStream( // since from here on it is not ever accessed by resolver functions. const itemPath = addPath(path, index, undefined); - if (isPromise(item)) { - completedResults.push( - completePromisedListItemValue( - item, - exeContext, - itemType, - fieldGroup, - info, - itemPath, - incrementalContext, - deferMap, - ), - ); - containsPromise = true; - } else if ( + if ( completeListItemValue( item, completedResults, @@ -1515,6 +1452,22 @@ function completeListItemValue( incrementalContext: IncrementalContext | undefined, deferMap: ReadonlyMap | undefined, ): boolean { + if (isPromise(item)) { + completedResults.push( + completePromisedValue( + exeContext, + itemType, + fieldGroup, + info, + itemPath, + item, + incrementalContext, + deferMap, + ), + ); + return true; + } + try { const completedItem = completeValue( exeContext, @@ -1561,45 +1514,6 @@ function completeListItemValue( return false; } -async function completePromisedListItemValue( - item: unknown, - exeContext: ExecutionContext, - itemType: GraphQLOutputType, - fieldGroup: FieldGroup, - info: GraphQLResolveInfo, - itemPath: Path, - incrementalContext: IncrementalContext | undefined, - deferMap: ReadonlyMap | undefined, -): Promise { - try { - const resolved = await item; - let completed = completeValue( - exeContext, - itemType, - fieldGroup, - info, - itemPath, - resolved, - incrementalContext, - deferMap, - ); - if (isPromise(completed)) { - completed = await completed; - } - return completed; - } catch (rawError) { - handleFieldError( - rawError, - exeContext, - itemType, - fieldGroup, - itemPath, - incrementalContext, - ); - return null; - } -} - /** * Complete a Scalar or Enum by serializing to a valid value, returning * null if serialization is not possible.