Skip to content

Commit 4450aa5

Browse files
committed
introduce addError instead of handleFieldError
addError calls locatedError and then adds the error as previously in handleFieldError, throwing if the type is non-null
1 parent f291207 commit 4450aa5

File tree

1 file changed

+44
-14
lines changed

1 file changed

+44
-14
lines changed

src/execution/execute.ts

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -708,8 +708,13 @@ function executeField(
708708
result = resolveFn(source, args, contextValue, info);
709709
} catch (rawError) {
710710
const errors = asyncPayloadRecord?.errors ?? exeContext.errors;
711-
const error = locatedError(rawError, fieldNodes, pathToArray(path));
712-
const handledError = handleFieldError(error, returnType, errors);
711+
const handledError = addError(
712+
rawError,
713+
fieldNodes,
714+
returnType,
715+
path,
716+
errors,
717+
);
713718
filterSubsequentPayloads(exeContext, path, asyncPayloadRecord);
714719
return handledError;
715720
}
@@ -762,8 +767,13 @@ function completePromiseCatchingErrors(
762767
// Note: we don't rely on a `catch` method, but we do expect "thenable"
763768
// to take a second callback for the error case.
764769
const errors = asyncPayloadRecord?.errors ?? exeContext.errors;
765-
const error = locatedError(rawError, fieldNodes, pathToArray(path));
766-
const handledError = handleFieldError(error, returnType, errors);
770+
const handledError = addError(
771+
rawError,
772+
fieldNodes,
773+
returnType,
774+
path,
775+
errors,
776+
);
767777
filterSubsequentPayloads(exeContext, path, asyncPayloadRecord);
768778
return handledError;
769779
});
@@ -791,8 +801,13 @@ function completeValueCatchingErrors(
791801
);
792802
} catch (rawError) {
793803
const errors = asyncPayloadRecord?.errors ?? exeContext.errors;
794-
const error = locatedError(rawError, fieldNodes, pathToArray(path));
795-
const handledError = handleFieldError(error, returnType, errors);
804+
const handledError = addError(
805+
rawError,
806+
fieldNodes,
807+
returnType,
808+
path,
809+
errors,
810+
);
796811
filterSubsequentPayloads(exeContext, path, asyncPayloadRecord);
797812
return handledError;
798813
}
@@ -802,8 +817,13 @@ function completeValueCatchingErrors(
802817
// to take a second callback for the error case.
803818
completedItem = completedItem.then(undefined, (rawError) => {
804819
const errors = asyncPayloadRecord?.errors ?? exeContext.errors;
805-
const error = locatedError(rawError, fieldNodes, pathToArray(path));
806-
const handledError = handleFieldError(error, returnType, errors);
820+
const handledError = addError(
821+
rawError,
822+
fieldNodes,
823+
returnType,
824+
path,
825+
errors,
826+
);
807827
filterSubsequentPayloads(exeContext, path, asyncPayloadRecord);
808828
return handledError;
809829
});
@@ -838,11 +858,15 @@ export function buildResolveInfo(
838858
};
839859
}
840860

841-
function handleFieldError(
842-
error: GraphQLError,
861+
function addError(
862+
rawError: unknown,
863+
fieldNodes: ReadonlyArray<FieldNode>,
843864
returnType: GraphQLOutputType,
865+
path: Path,
844866
errors: Array<GraphQLError>,
845867
): null {
868+
const error = locatedError(rawError, fieldNodes, pathToArray(path));
869+
846870
// If the field type is non-nullable, then it is resolved without any
847871
// protection from errors, however it still properly locates the error.
848872
if (isNonNullType(returnType)) {
@@ -1066,8 +1090,9 @@ async function completeAsyncIteratorValue(
10661090
// eslint-disable-next-line no-await-in-loop
10671091
iteration = await iterator.next();
10681092
} catch (rawError) {
1069-
const error = locatedError(rawError, fieldNodes, pathToArray(itemPath));
1070-
completedResults.push(handleFieldError(error, itemType, errors));
1093+
completedResults.push(
1094+
addError(rawError, fieldNodes, itemType, itemPath, errors),
1095+
);
10711096
break;
10721097
}
10731098

@@ -2013,8 +2038,13 @@ async function executeStreamAsyncIteratorItem(
20132038
try {
20142039
iteration = await iterator.next();
20152040
} catch (rawError) {
2016-
const error = locatedError(rawError, fieldNodes, pathToArray(itemPath));
2017-
const value = handleFieldError(error, itemType, asyncPayloadRecord.errors);
2041+
const value = addError(
2042+
rawError,
2043+
fieldNodes,
2044+
itemType,
2045+
itemPath,
2046+
asyncPayloadRecord.errors,
2047+
);
20182048
// don't continue if iterator throws
20192049
return { done: true, value };
20202050
}

0 commit comments

Comments
 (0)