diff --git a/src/execution/execute.ts b/src/execution/execute.ts index 23bfa50702..42e3b9adf8 100644 --- a/src/execution/execute.ts +++ b/src/execution/execute.ts @@ -1107,19 +1107,17 @@ async function completeAsyncIteratorValue( /* c8 ignore start */ if (isPromise(item)) { completedResults.push( - completePromisedValue( + completePromisedListItemValue( + item, + graphqlWrappedResult, exeContext, itemType, fieldGroup, info, itemPath, - item, incrementalContext, deferMap, - ).then((resolved) => { - graphqlWrappedResult[1].push(...resolved[1]); - return resolved[0]; - }), + ), ); containsPromise = true; } else if ( @@ -1232,19 +1230,17 @@ function completeListValue( if (isPromise(item)) { completedResults.push( - completePromisedValue( + completePromisedListItemValue( + item, + graphqlWrappedResult, exeContext, itemType, fieldGroup, info, itemPath, - item, incrementalContext, deferMap, - ).then((resolved) => { - graphqlWrappedResult[1].push(...resolved[1]); - return resolved[0]; - }), + ), ); containsPromise = true; } else if ( @@ -1334,6 +1330,41 @@ function completeListItemValue( return false; } +async function completePromisedListItemValue( + item: unknown, + parent: GraphQLWrappedResult>, + 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; + } + parent[1].push(...completed[1]); + return completed[0]; + } catch (rawError) { + const errors = (incrementalContext ?? exeContext).errors; + handleFieldError(rawError, itemType, fieldGroup, itemPath, errors); + return null; + } +} + /** * Complete a Scalar or Enum by serializing to a valid value, returning * null if serialization is not possible.