Skip to content

Commit 25db102

Browse files
committed
refactor: introduce handleRawError
1 parent 0c7165a commit 25db102

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

@@ -525,15 +526,13 @@ function executeField(
525526
if (isPromise(completed)) {
526527
// Note: we don't rely on a `catch` method, but we do expect "thenable"
527528
// to take a second callback for the error case.
528-
return completed.then(undefined, (rawError) => {
529-
const error = locatedError(rawError, fieldNodes, pathToArray(path));
530-
return handleFieldError(error, returnType, exeContext);
531-
});
529+
return completed.then(undefined, (rawError) =>
530+
handleRawError(exeContext, returnType, rawError, fieldNodes, path),
531+
);
532532
}
533533
return completed;
534534
} catch (rawError) {
535-
const error = locatedError(rawError, fieldNodes, pathToArray(path));
536-
return handleFieldError(error, returnType, exeContext);
535+
return handleRawError(exeContext, returnType, rawError, fieldNodes, path);
537536
}
538537
}
539538

@@ -563,11 +562,15 @@ export function buildResolveInfo(
563562
};
564563
}
565564

566-
function handleFieldError(
567-
error: GraphQLError,
568-
returnType: GraphQLOutputType,
565+
function handleRawError(
569566
exeContext: ExecutionContext,
567+
returnType: GraphQLOutputType,
568+
rawError: unknown,
569+
fieldNodes: ReadonlyArray<ASTNode>,
570+
path?: Maybe<Readonly<Path>>,
570571
): null {
572+
const error = locatedError(rawError, fieldNodes, pathToArray(path));
573+
571574
// If the field type is non-nullable, then it is resolved without any
572575
// protection from errors, however it still properly locates the error.
573576
if (isNonNullType(returnType)) {
@@ -743,19 +746,19 @@ function completeListValue(
743746
containsPromise = true;
744747
// Note: we don't rely on a `catch` method, but we do expect "thenable"
745748
// to take a second callback for the error case.
746-
return completedItem.then(undefined, (rawError) => {
747-
const error = locatedError(
748-
rawError,
749-
fieldNodes,
750-
pathToArray(itemPath),
751-
);
752-
return handleFieldError(error, itemType, exeContext);
753-
});
749+
return completedItem.then(undefined, (rawError) =>
750+
handleRawError(exeContext, itemType, rawError, fieldNodes, itemPath),
751+
);
754752
}
755753
return completedItem;
756754
} catch (rawError) {
757-
const error = locatedError(rawError, fieldNodes, pathToArray(itemPath));
758-
return handleFieldError(error, itemType, exeContext);
755+
return handleRawError(
756+
exeContext,
757+
itemType,
758+
rawError,
759+
fieldNodes,
760+
itemPath,
761+
);
759762
}
760763
});
761764

0 commit comments

Comments
 (0)