Skip to content

Commit bd0f235

Browse files
committed
EPR completeValueWithLocatedError
1 parent 44a6d0f commit bd0f235

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/execution/execute.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -856,14 +856,19 @@ function completeValueCatchingError(
856856
// If the field type is non-nullable, then it is resolved without any
857857
// protection from errors, however it still properly locates the error.
858858
if (isNonNullType(returnType)) {
859-
return completeValueWithLocatedError(
859+
const completed = completeValueWithLocatedError(
860860
exeContext,
861861
returnType,
862862
fieldNodes,
863863
info,
864864
path,
865865
result,
866866
);
867+
const promise = getPromise(completed);
868+
if (promise) {
869+
return promise.then(r => r.data);
870+
}
871+
return completed.data;
867872
}
868873

869874
// Otherwise, error protection is applied, logging the error and resolving
@@ -883,12 +888,12 @@ function completeValueCatchingError(
883888
// the rejection error and resolve to null.
884889
// Note: we don't rely on a `catch` method, but we do expect "thenable"
885890
// to take a second callback for the error case.
886-
return promise.then(undefined, error => {
891+
return promise.then(r => r.data).then(undefined, error => {
887892
exeContext.errors.push(error);
888893
return null;
889894
});
890895
}
891-
return completed;
896+
return completed.data;
892897
} catch (error) {
893898
// If `completeValueWithLocatedError` returned abruptly (threw an error),
894899
// log the error and return null.
@@ -906,7 +911,7 @@ function completeValueWithLocatedError(
906911
info: GraphQLResolveInfo,
907912
path: ResponsePath,
908913
result: mixed,
909-
): mixed {
914+
): ExecutionPartialResult<mixed> {
910915
try {
911916
const completed = completeValue(
912917
exeContext,
@@ -918,7 +923,7 @@ function completeValueWithLocatedError(
918923
);
919924
const promise = getPromise(completed);
920925
if (promise) {
921-
return promise.then(r => r.data).then(undefined, error =>
926+
return promise.then(undefined, error =>
922927
Promise.reject(
923928
locatedError(
924929
asErrorInstance(error),
@@ -928,7 +933,7 @@ function completeValueWithLocatedError(
928933
),
929934
);
930935
}
931-
return completed.data;
936+
return completed;
932937
} catch (error) {
933938
throw locatedError(
934939
asErrorInstance(error),

0 commit comments

Comments
 (0)