Skip to content

Commit

Permalink
introduce handleRawError
Browse files Browse the repository at this point in the history
to include filtering
  • Loading branch information
yaacovCR committed Oct 4, 2022
1 parent 09ed033 commit e1074d8
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions src/execution/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -769,6 +767,20 @@ export function buildResolveInfo(
};
}

function handleRawError(
rawError: unknown,
exeContext: ExecutionContext,
fieldNodes: ReadonlyArray<FieldNode>,
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<FieldNode>,
Expand Down Expand Up @@ -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;
}
}

Expand All @@ -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)) {
Expand Down

0 comments on commit e1074d8

Please sign in to comment.