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.

(core) - Fix stale on reexecute being skipped for cache-first (#1755)

* (core) - Fix stale on reexectuted operation being skipped for cache-first

* Fix stale reexecution logic being applied to subscriptions

authored by

Phil Pluckthun and committed by
GitHub
c9cfa589 67e15263

+21 -13
+5
.changeset/fresh-moose-exist.md
··· 1 + --- 2 + '@urql/core': patch 3 + --- 4 + 5 + Fix accidental change in passive `stale: true`, where a `cache-first` operation issued by Graphcache wouldn't yield an affected query and update its result to reflect the loading state with `stale: true`. This is a regression from `v2.1.0` and mostly becomes unexpected when `cache.invalidate(...)` is used.
+10 -5
packages/core/src/client.test.ts
··· 6 6 Source, 7 7 delay, 8 8 map, 9 + never, 9 10 pipe, 11 + merge, 10 12 subscribe, 11 13 publish, 12 14 filter, ··· 869 871 870 872 it('does nothing when operation is a subscription has been emitted yet', () => { 871 873 const exchange: Exchange = () => ops$ => { 872 - return pipe( 873 - ops$, 874 - map(op => ({ data: 1, operation: op })), 875 - take(1) 876 - ); 874 + return merge([ 875 + pipe( 876 + ops$, 877 + map(op => ({ data: 1, operation: op })), 878 + take(1) 879 + ), 880 + never, 881 + ]); 877 882 }; 878 883 879 884 const client = createClient({
+6 -8
packages/core/src/client.ts
··· 206 206 ) 207 207 ), 208 208 switchMap(result => { 209 - if (result.stale) { 209 + if (operation.kind !== 'query' || result.stale) { 210 210 return fromValue(result); 211 211 } 212 212 ··· 215 215 // Mark a result as stale when a new operation is sent for it 216 216 pipe( 217 217 operations$, 218 - filter(op => { 219 - return ( 220 - op.kind === operation.kind && 218 + filter( 219 + op => 220 + op.kind === 'query' && 221 221 op.key === operation.key && 222 - (op.context.requestPolicy === 'network-only' || 223 - op.context.requestPolicy === 'cache-and-network') 224 - ); 225 - }), 222 + op.context.requestPolicy !== 'cache-only' 223 + ), 226 224 take(1), 227 225 map(() => ({ ...result, stale: true })) 228 226 ),