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

fix(bindings): Fix handlers for subscriptions receiving null (#3581)

authored by kitten.sh and committed by

GitHub 9272cefa 0204e044

+18 -6
+8
.changeset/famous-deers-marry.md
··· 1 + --- 2 + '@urql/preact': patch 3 + '@urql/svelte': patch 4 + 'urql': patch 5 + '@urql/vue': patch 6 + --- 7 + 8 + Fix subscription handlers to not receive `null` values.
+1 -1
packages/preact-urql/src/hooks/useSubscription.ts
··· 282 282 const { current: handler } = handlerRef; 283 283 // If a handler has been passed, it's used to merge new data in 284 284 const data = 285 - partial.data !== undefined 285 + partial.data != null 286 286 ? typeof handler === 'function' 287 287 ? handler(result.data, partial.data) 288 288 : partial.data
+6 -2
packages/react-urql/src/hooks/useSubscription.ts
··· 266 266 deferDispatch(setState, state => { 267 267 const nextResult = computeNextState(state[1], result); 268 268 if (state[1] === nextResult) return state; 269 - if (handlerRef.current && state[1].data !== nextResult.data) { 269 + if ( 270 + handlerRef.current && 271 + nextResult.data != null && 272 + state[1].data !== nextResult.data 273 + ) { 270 274 nextResult.data = handlerRef.current( 271 275 state[1].data, 272 - nextResult.data! 276 + nextResult.data 273 277 ) as any; 274 278 } 275 279
+1 -1
packages/svelte-urql/src/subscriptionStore.ts
··· 183 183 ), 184 184 scan((result: OperationResultState<Result, Variables>, partial) => { 185 185 const data = 186 - partial.data !== undefined 186 + partial.data != null 187 187 ? typeof handler === 'function' 188 188 ? handler(result.data, partial.data) 189 189 : partial.data
+2 -2
packages/vue-urql/src/useSubscription.ts
··· 306 306 subscribe(result => { 307 307 fetching.value = true; 308 308 data.value = 309 - result.data !== undefined 309 + result.data != null 310 310 ? typeof scanHandler.value === 'function' 311 - ? scanHandler.value(data.value as any, result.data!) 311 + ? scanHandler.value(data.value as any, result.data) 312 312 : result.data 313 313 : (result.data as any); 314 314 error.value = result.error;