diff --git a/src/execution/execute.ts b/src/execution/execute.ts index f7a4387c0e6..57c66823bf4 100644 --- a/src/execution/execute.ts +++ b/src/execution/execute.ts @@ -703,16 +703,14 @@ function executeField( result = resolveFn(source, args, contextValue, info); } catch (rawError) { - const errors = asyncPayloadRecord?.errors ?? exeContext.errors; - const handledError = addError( + return handleRawError( rawError, + exeContext, fieldNodes, returnType, path, - errors, + asyncPayloadRecord, ); - filterSubsequentPayloads(exeContext, path, asyncPayloadRecord); - return handledError; } if (isPromise(result)) { @@ -765,6 +763,20 @@ export function buildResolveInfo( }; } +function handleRawError( + rawError: unknown, + exeContext: ExecutionContext, + fieldNodes: ReadonlyArray, + returnType: GraphQLOutputType, + path: Path, + asyncPayloadRecord: AsyncPayloadRecord | undefined, +): null { + const errors = asyncPayloadRecord?.errors ?? exeContext.errors; + addError(rawError, fieldNodes, returnType, path, errors); + filterSubsequentPayloads(exeContext, path, asyncPayloadRecord); + return null; +} + function addError( rawError: unknown, fieldNodes: ReadonlyArray, @@ -926,16 +938,14 @@ async function completePromiseCatchingErrors( } return completed; } catch (rawError) { - const errors = asyncPayloadRecord?.errors ?? exeContext.errors; - const handledError = addError( + return handleRawError( rawError, + exeContext, fieldNodes, returnType, path, - errors, + asyncPayloadRecord, ); - filterSubsequentPayloads(exeContext, path, asyncPayloadRecord); - return handledError; } } @@ -960,16 +970,14 @@ function completeValueCatchingErrors( asyncPayloadRecord, ); } catch (rawError) { - const errors = asyncPayloadRecord?.errors ?? exeContext.errors; - const handledError = addError( + return handleRawError( rawError, + exeContext, fieldNodes, returnType, path, - errors, + asyncPayloadRecord, ); - filterSubsequentPayloads(exeContext, path, asyncPayloadRecord); - return handledError; } if (isPromise(completedValue)) {