From 3e10da6b2bf97bdf40317a6d88a0cc6412fd0974 Mon Sep 17 00:00:00 2001 From: Laurin Quast Date: Mon, 11 Mar 2024 11:11:23 +0100 Subject: [PATCH] fix: revert subscription event source stream handling (#5965) * fix: revert subscription event source stream handling * fix: wrap error * test: ensure location is there * better assertion condition --- .changeset/spotty-ways-give.md | 5 +++++ .../src/execution/__tests__/subscribe-test.ts | 15 +++------------ packages/executor/src/execution/execute.ts | 6 ++---- 3 files changed, 10 insertions(+), 16 deletions(-) create mode 100644 .changeset/spotty-ways-give.md diff --git a/.changeset/spotty-ways-give.md b/.changeset/spotty-ways-give.md new file mode 100644 index 00000000000..c9a779dd9f1 --- /dev/null +++ b/.changeset/spotty-ways-give.md @@ -0,0 +1,5 @@ +--- +"@graphql-tools/executor": patch +--- + +revert subscription event source error handling to graphql-js behaviour diff --git a/packages/executor/src/execution/__tests__/subscribe-test.ts b/packages/executor/src/execution/__tests__/subscribe-test.ts index 9c6132f19f4..a0f64c26e5c 100644 --- a/packages/executor/src/execution/__tests__/subscribe-test.ts +++ b/packages/executor/src/execution/__tests__/subscribe-test.ts @@ -1287,18 +1287,9 @@ describe('Subscription Publish Phase', () => { }, }); - const resultThree = await iterator.next(); - - expect(JSON.parse(JSON.stringify(resultThree))).toEqual({ - done: false, - value: { - errors: [ - { - message: 'test error', - locations: [{ line: 2, column: 9 }], - }, - ], - }, + await expect(iterator.next()).rejects.toMatchObject({ + message: 'test error', + locations: [{ line: 2, column: 9 }], }); const endResult = await iterator.next(); diff --git a/packages/executor/src/execution/execute.ts b/packages/executor/src/execution/execute.ts index e90e3e7c89e..fc7a802afef 100644 --- a/packages/executor/src/execution/execute.ts +++ b/packages/executor/src/execution/execute.ts @@ -1631,14 +1631,12 @@ function mapSourceToResponse( await executeImpl(buildPerEventExecutionContext(exeContext, payload)), exeContext.signal, ), - async function* (error: Error) { + (error: Error) => { const wrappedError = createGraphQLError(error.message, { originalError: error, nodes: [exeContext.operation], }); - yield { - errors: [wrappedError], - }; + throw wrappedError; }, ), );