diff --git a/src/execution/__tests__/abort-signal-test.ts b/src/execution/__tests__/abort-signal-test.ts index 7e34c3dc91..acf6ec623b 100644 --- a/src/execution/__tests__/abort-signal-test.ts +++ b/src/execution/__tests__/abort-signal-test.ts @@ -100,8 +100,6 @@ describe('Execute: Cancellation', () => { errors: [ { message: 'Aborted', - path: ['todo', 'id'], - locations: [{ line: 4, column: 11 }], }, ], }); @@ -149,8 +147,6 @@ describe('Execute: Cancellation', () => { errors: [ { message: 'Aborted', - path: ['todo', 'author', 'id'], - locations: [{ line: 6, column: 13 }], }, ], }); @@ -198,8 +194,6 @@ describe('Execute: Cancellation', () => { errors: [ { message: 'Aborted', - path: ['todo', 'id'], - locations: [{ line: 4, column: 11 }], }, ], }); @@ -261,14 +255,7 @@ describe('Execute: Cancellation', () => { { errors: [ { - locations: [ - { - column: 13, - line: 6, - }, - ], message: 'Aborted', - path: ['todo', 'text'], }, ], id: '0', @@ -304,15 +291,10 @@ describe('Execute: Cancellation', () => { const result = await resultPromise; expectJSON(result).toDeepEqual({ - data: { - foo: 'baz', - bar: null, - }, + data: null, errors: [ { message: 'Aborted', - path: ['bar'], - locations: [{ line: 4, column: 9 }], }, ], }); diff --git a/src/execution/execute.ts b/src/execution/execute.ts index 5cfb8c1924..40554d90fd 100644 --- a/src/execution/execute.ts +++ b/src/execution/execute.ts @@ -518,7 +518,7 @@ export function validateExecutionArgs( } = args; if (abortSignal?.aborted) { - return [locatedError(new Error(abortSignal.reason), undefined)]; + return [new GraphQLError(abortSignal.reason)]; } // If the schema used for execution is invalid, throw an error. @@ -667,16 +667,9 @@ function executeFieldsSerially( const fieldPath = addPath(path, responseName, parentType.name); const abortSignal = exeContext.validatedExecutionArgs.abortSignal; if (abortSignal?.aborted) { - handleFieldError( - new Error(abortSignal.reason), - exeContext, - parentType, - fieldDetailsList, - fieldPath, - incrementalContext, - ); - graphqlWrappedResult[0][responseName] = null; - return graphqlWrappedResult; + throw new GraphQLError(abortSignal.reason, { + path: undefined, + }); } const result = executeField( @@ -731,11 +724,9 @@ function executeFields( const fieldPath = addPath(path, responseName, parentType.name); const abortSignal = exeContext.validatedExecutionArgs.abortSignal; if (abortSignal?.aborted) { - throw locatedError( - new Error(abortSignal.reason), - toNodes(fieldDetailsList), - pathToArray(fieldPath), - ); + throw new GraphQLError(abortSignal.reason, { + path: undefined, + }); } const result = executeField( @@ -934,10 +925,11 @@ function handleFieldError( path: Path, incrementalContext: IncrementalContext | undefined, ): void { + const isAborted = exeContext.validatedExecutionArgs.abortSignal?.aborted; const error = locatedError( rawError, - toNodes(fieldDetailsList), - pathToArray(path), + isAborted ? undefined : toNodes(fieldDetailsList), + isAborted ? undefined : pathToArray(path), ); // If the field type is non-nullable, then it is resolved without any