Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(core): Add missing error patching and support incremental results in subscriptionExchange (#3055)

authored by

Phil Pluckthun and committed by
GitHub
d80fea87 ec6adbe4

+27 -4
+5
.changeset/fuzzy-baboons-add.md
··· 1 + --- 2 + '@urql/core': minor 3 + --- 4 + 5 + Update `subscriptionExchange` to support incremental results out of the box. If a subscription proactively completes, results are also now updated with `hasNext: false`.
+5
.changeset/poor-pumpkins-greet.md
··· 1 + --- 2 + '@urql/core': patch 3 + --- 4 + 5 + Fix incremental results not merging `errors` from subsequent non-incremental results.
+15 -3
packages/core/src/exchanges/subscription.ts
··· 15 15 makeResult, 16 16 makeErrorResult, 17 17 makeOperation, 18 + mergeResultPatch, 18 19 } from '../utils'; 19 20 20 21 import { ··· 158 159 return make<OperationResult>(({ next, complete }) => { 159 160 let isComplete = false; 160 161 let sub: Subscription | void; 162 + let result: OperationResult | void; 161 163 162 164 Promise.resolve().then(() => { 163 165 if (isComplete) return; 164 166 165 167 sub = observableish.subscribe({ 166 - next: result => next(makeResult(operation, result)), 167 - error: err => next(makeErrorResult(operation, err)), 168 - complete: () => { 168 + next(nextResult) { 169 + next( 170 + (result = result 171 + ? mergeResultPatch(result, nextResult) 172 + : makeResult(operation, nextResult)) 173 + ); 174 + }, 175 + error(error) { 176 + next(makeErrorResult(operation, error)); 177 + }, 178 + complete() { 169 179 if (!isComplete) { 170 180 isComplete = true; 171 181 if (operation.kind === 'subscription') { ··· 174 184 ); 175 185 } 176 186 187 + if (result && result.hasNext) 188 + next(mergeResultPatch(result, { hasNext: false })); 177 189 complete(); 178 190 } 179 191 },
+2 -1
packages/core/src/utils/result.ts
··· 71 71 response?: any 72 72 ): OperationResult => { 73 73 let data: ExecutionResult['data']; 74 + let errors = prevResult.error ? prevResult.error.graphQLErrors : []; 74 75 let hasExtensions = !!prevResult.extensions || !!nextResult.extensions; 75 76 const extensions = { ...prevResult.extensions, ...nextResult.extensions }; 76 - const errors = prevResult.error ? prevResult.error.graphQLErrors : []; 77 77 78 78 let incremental = nextResult.incremental; 79 79 ··· 115 115 } 116 116 } else { 117 117 data = nextResult.data || prevResult.data; 118 + errors = (nextResult.errors as any[]) || errors; 118 119 } 119 120 120 121 return {