Skip to content

Commit 74a8a4c

Browse files
committed
fix where cancellation happens for objects
extracted from graphql#4259
1 parent ebb064e commit 74a8a4c

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

src/execution/__tests__/abort-signal-test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ describe('Execute: Cancellation', () => {
7171
errors: [
7272
{
7373
message: 'Aborted',
74-
path: ['todo', 'id'],
75-
locations: [{ line: 4, column: 11 }],
74+
path: ['todo'],
75+
locations: [{ line: 3, column: 9 }],
7676
},
7777
],
7878
});
@@ -120,8 +120,8 @@ describe('Execute: Cancellation', () => {
120120
errors: [
121121
{
122122
message: 'Aborted',
123-
path: ['todo', 'author', 'id'],
124-
locations: [{ line: 6, column: 13 }],
123+
path: ['todo', 'author'],
124+
locations: [{ line: 5, column: 11 }],
125125
},
126126
],
127127
});
@@ -169,8 +169,8 @@ describe('Execute: Cancellation', () => {
169169
errors: [
170170
{
171171
message: 'Aborted',
172-
path: ['todo', 'id'],
173-
locations: [{ line: 4, column: 11 }],
172+
path: ['todo'],
173+
locations: [{ line: 3, column: 9 }],
174174
},
175175
],
176176
});

src/execution/execute.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -534,15 +534,6 @@ function executeFields(
534534
try {
535535
for (const [responseName, fieldDetailsList] of groupedFieldSet) {
536536
const fieldPath = addPath(path, responseName, parentType.name);
537-
const abortSignal = exeContext.validatedExecutionArgs.abortSignal;
538-
if (abortSignal?.aborted) {
539-
throw locatedError(
540-
new Error(abortSignal.reason),
541-
toNodes(fieldDetailsList),
542-
pathToArray(fieldPath),
543-
);
544-
}
545-
546537
const result = executeField(
547538
exeContext,
548539
parentType,
@@ -1274,13 +1265,23 @@ function completeObjectValue(
12741265
path: Path,
12751266
result: unknown,
12761267
): PromiseOrValue<ObjMap<unknown>> {
1268+
const validatedExecutionArgs = exeContext.validatedExecutionArgs;
1269+
const abortSignal = validatedExecutionArgs.abortSignal;
1270+
if (abortSignal?.aborted) {
1271+
throw locatedError(
1272+
new Error(abortSignal.reason),
1273+
toNodes(fieldDetailsList),
1274+
pathToArray(path),
1275+
);
1276+
}
1277+
12771278
// If there is an isTypeOf predicate function, call it with the
12781279
// current result. If isTypeOf returns false, then raise an error rather
12791280
// than continuing execution.
12801281
if (returnType.isTypeOf) {
12811282
const isTypeOf = returnType.isTypeOf(
12821283
result,
1283-
exeContext.validatedExecutionArgs.contextValue,
1284+
validatedExecutionArgs.contextValue,
12841285
info,
12851286
);
12861287

0 commit comments

Comments
 (0)