From e1074d816c0ae899e0f3ae087657bed660101827 Mon Sep 17 00:00:00 2001 From: Yaacov Rydzinski Date: Fri, 30 Sep 2022 15:38:41 +0300 Subject: [PATCH] introduce handleRawError to include filtering --- src/execution/execute.ts | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/execution/execute.ts b/src/execution/execute.ts index 79ee5923b13..76fe25f8fee 100644 --- a/src/execution/execute.ts +++ b/src/execution/execute.ts @@ -707,16 +707,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)) { @@ -769,6 +767,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, @@ -930,16 +942,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; } } @@ -964,16 +974,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)) {