From 92387d48f4e5d4e1d2fb767d811177909873dddc Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Wed, 15 Mar 2023 17:33:37 +0000 Subject: [PATCH 1/4] Add missing errors merging when non-incremental result is merged --- packages/core/src/utils/result.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/core/src/utils/result.ts b/packages/core/src/utils/result.ts index d5f54bb5a5..16e7cb18d8 100644 --- a/packages/core/src/utils/result.ts +++ b/packages/core/src/utils/result.ts @@ -71,9 +71,9 @@ export const mergeResultPatch = ( response?: any ): OperationResult => { let data: ExecutionResult['data']; + let errors = prevResult.error ? prevResult.error.graphQLErrors : []; let hasExtensions = !!prevResult.extensions || !!nextResult.extensions; const extensions = { ...prevResult.extensions, ...nextResult.extensions }; - const errors = prevResult.error ? prevResult.error.graphQLErrors : []; let incremental = nextResult.incremental; @@ -115,6 +115,7 @@ export const mergeResultPatch = ( } } else { data = nextResult.data || prevResult.data; + errors = (nextResult.errors as any[]) || errors; } return { From 1709b60f6a6a72d5188a84dc979b9b46321c2403 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Wed, 15 Mar 2023 17:39:11 +0000 Subject: [PATCH 2/4] Add changeset --- .changeset/poor-pumpkins-greet.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/poor-pumpkins-greet.md diff --git a/.changeset/poor-pumpkins-greet.md b/.changeset/poor-pumpkins-greet.md new file mode 100644 index 0000000000..6fd4a0dff8 --- /dev/null +++ b/.changeset/poor-pumpkins-greet.md @@ -0,0 +1,5 @@ +--- +'@urql/core': patch +--- + +Fix incremental results not merging `errors` from subsequent non-incremental results. From 2478b1b181c950ffd55e4de3f77ac2788b28ee88 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Wed, 15 Mar 2023 17:39:17 +0000 Subject: [PATCH 3/4] Update subscriptionExchange with incremental support --- packages/core/src/exchanges/subscription.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/core/src/exchanges/subscription.ts b/packages/core/src/exchanges/subscription.ts index c8efdc060c..45a4b4ee4e 100644 --- a/packages/core/src/exchanges/subscription.ts +++ b/packages/core/src/exchanges/subscription.ts @@ -15,6 +15,7 @@ import { makeResult, makeErrorResult, makeOperation, + mergeResultPatch, } from '../utils'; import { @@ -158,14 +159,23 @@ export const subscriptionExchange = ({ return make(({ next, complete }) => { let isComplete = false; let sub: Subscription | void; + let result: OperationResult | void; Promise.resolve().then(() => { if (isComplete) return; sub = observableish.subscribe({ - next: result => next(makeResult(operation, result)), - error: err => next(makeErrorResult(operation, err)), - complete: () => { + next(nextResult) { + next( + (result = result + ? mergeResultPatch(result, nextResult) + : makeResult(operation, nextResult)) + ); + }, + error(error) { + next(makeErrorResult(operation, error)); + }, + complete() { if (!isComplete) { isComplete = true; if (operation.kind === 'subscription') { @@ -174,6 +184,8 @@ export const subscriptionExchange = ({ ); } + if (result && result.hasNext) + next(mergeResultPatch(result, { hasNext: false })); complete(); } }, From 447511aecfd8e20127193207e87f97e467a4f4aa Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Wed, 15 Mar 2023 17:40:33 +0000 Subject: [PATCH 4/4] Add changeset --- .changeset/fuzzy-baboons-add.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/fuzzy-baboons-add.md diff --git a/.changeset/fuzzy-baboons-add.md b/.changeset/fuzzy-baboons-add.md new file mode 100644 index 0000000000..78f0a68836 --- /dev/null +++ b/.changeset/fuzzy-baboons-add.md @@ -0,0 +1,5 @@ +--- +'@urql/core': minor +--- + +Update `subscriptionExchange` to support incremental results out of the box. If a subscription proactively completes, results are also now updated with `hasNext: false`.