Skip to content

Commit 438b29a

Browse files
committed
inline handleAsyncCompletionError
1 parent 03aac5f commit 438b29a

File tree

1 file changed

+24
-43
lines changed

1 file changed

+24
-43
lines changed

src/execution/execute.ts

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -746,14 +746,13 @@ function executeField(
746746
);
747747

748748
if (isPromise(completed)) {
749-
return handleAsyncCompletionError(
750-
completed,
751-
exeContext,
752-
returnType,
753-
fieldNodes,
754-
path,
755-
asyncPayloadRecord,
756-
);
749+
return catchAfter(completed, (rawError) => {
750+
const errors = asyncPayloadRecord?.errors ?? exeContext.errors;
751+
const error = locatedError(rawError, fieldNodes, pathToArray(path));
752+
const handledError = handleFieldError(error, returnType, errors);
753+
filterSubsequentPayloads(exeContext, path, asyncPayloadRecord);
754+
return handledError;
755+
});
757756
}
758757
return completed;
759758
} catch (rawError) {
@@ -765,25 +764,6 @@ function executeField(
765764
}
766765
}
767766

768-
async function handleAsyncCompletionError(
769-
promised: Promise<unknown>,
770-
exeContext: ExecutionContext,
771-
returnType: GraphQLOutputType,
772-
fieldNodes: ReadonlyArray<FieldNode>,
773-
path: Path,
774-
asyncPayloadRecord?: AsyncPayloadRecord,
775-
): Promise<unknown> {
776-
try {
777-
return await promised;
778-
} catch (rawError) {
779-
const errors = asyncPayloadRecord?.errors ?? exeContext.errors;
780-
const error = locatedError(rawError, fieldNodes, pathToArray(path));
781-
const handledError = handleFieldError(error, returnType, errors);
782-
filterSubsequentPayloads(exeContext, path, asyncPayloadRecord);
783-
return handledError;
784-
}
785-
}
786-
787767
/**
788768
* TODO: consider no longer exporting this function
789769
* @internal
@@ -1240,14 +1220,16 @@ function completeListItemValue(
12401220
// Note: we don't rely on a `catch` method, but we do expect "thenable"
12411221
// to take a second callback for the error case.
12421222
completedResults.push(
1243-
handleAsyncCompletionError(
1244-
completedItem,
1245-
exeContext,
1246-
itemType,
1247-
fieldNodes,
1248-
itemPath,
1249-
asyncPayloadRecord,
1250-
),
1223+
catchAfter(completedItem, (rawError) => {
1224+
const error = locatedError(
1225+
rawError,
1226+
fieldNodes,
1227+
pathToArray(itemPath),
1228+
);
1229+
const handledError = handleFieldError(error, itemType, errors);
1230+
filterSubsequentPayloads(exeContext, itemPath, asyncPayloadRecord);
1231+
return handledError;
1232+
}),
12511233
);
12521234

12531235
return true;
@@ -2059,14 +2041,13 @@ async function executeStreamIteratorItem(
20592041
);
20602042

20612043
if (isPromise(completedItem)) {
2062-
completedItem = handleAsyncCompletionError(
2063-
completedItem,
2064-
exeContext,
2065-
itemType,
2066-
fieldNodes,
2067-
itemPath,
2068-
asyncPayloadRecord,
2069-
);
2044+
completedItem = catchAfter(completedItem, (rawError) => {
2045+
const errors = asyncPayloadRecord?.errors ?? exeContext.errors;
2046+
const error = locatedError(rawError, fieldNodes, pathToArray(itemPath));
2047+
const handledError = handleFieldError(error, itemType, errors);
2048+
filterSubsequentPayloads(exeContext, itemPath, asyncPayloadRecord);
2049+
return handledError;
2050+
});
20702051
}
20712052
return { done: false, value: completedItem };
20722053
} catch (rawError) {

0 commit comments

Comments
 (0)