Skip to content

Commit 32fda3b

Browse files
committed
refactor: introduce handleRawError
1 parent df1bdda commit 32fda3b

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

src/execution/execute.ts

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import type {
2222
OperationDefinitionNode,
2323
FieldNode,
2424
FragmentDefinitionNode,
25+
ASTNode,
2526
} from '../language/ast';
2627
import { Kind } from '../language/kinds';
2728

@@ -504,15 +505,13 @@ function executeField(
504505
if (isPromise(completed)) {
505506
// Note: we don't rely on a `catch` method, but we do expect "thenable"
506507
// to take a second callback for the error case.
507-
return completed.then(undefined, (rawError) => {
508-
const error = locatedError(rawError, fieldNodes, pathToArray(path));
509-
return handleFieldError(error, returnType, exeContext);
510-
});
508+
return completed.then(undefined, (rawError) =>
509+
handleRawError(exeContext, returnType, rawError, fieldNodes, path),
510+
);
511511
}
512512
return completed;
513513
} catch (rawError) {
514-
const error = locatedError(rawError, fieldNodes, pathToArray(path));
515-
return handleFieldError(error, returnType, exeContext);
514+
return handleRawError(exeContext, returnType, rawError, fieldNodes, path);
516515
}
517516
}
518517

@@ -542,11 +541,15 @@ export function buildResolveInfo(
542541
};
543542
}
544543

545-
function handleFieldError(
546-
error: GraphQLError,
547-
returnType: GraphQLOutputType,
544+
function handleRawError(
548545
exeContext: ExecutionContext,
546+
returnType: GraphQLOutputType,
547+
rawError: unknown,
548+
fieldNodes: ReadonlyArray<ASTNode>,
549+
path?: Maybe<Readonly<Path>>,
549550
): null {
551+
const error = locatedError(rawError, fieldNodes, pathToArray(path));
552+
550553
// If the field type is non-nullable, then it is resolved without any
551554
// protection from errors, however it still properly locates the error.
552555
if (isNonNullType(returnType)) {
@@ -722,19 +725,19 @@ function completeListValue(
722725
containsPromise = true;
723726
// Note: we don't rely on a `catch` method, but we do expect "thenable"
724727
// to take a second callback for the error case.
725-
return completedItem.then(undefined, (rawError) => {
726-
const error = locatedError(
727-
rawError,
728-
fieldNodes,
729-
pathToArray(itemPath),
730-
);
731-
return handleFieldError(error, itemType, exeContext);
732-
});
728+
return completedItem.then(undefined, (rawError) =>
729+
handleRawError(exeContext, itemType, rawError, fieldNodes, itemPath),
730+
);
733731
}
734732
return completedItem;
735733
} catch (rawError) {
736-
const error = locatedError(rawError, fieldNodes, pathToArray(itemPath));
737-
return handleFieldError(error, itemType, exeContext);
734+
return handleRawError(
735+
exeContext,
736+
itemType,
737+
rawError,
738+
fieldNodes,
739+
itemPath,
740+
);
738741
}
739742
});
740743

0 commit comments

Comments
 (0)