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 cache-only for the caches (#551)

* fix cache-only for the default document-cache

* fix cache-only for graphCache

* add changeset

* Update exchanges/graphcache/src/cacheExchange.ts

Co-Authored-By: Andy Richardson <andy.john.richardson@gmail.com>

* Update packages/core/src/exchanges/cache.ts

Co-Authored-By: Phil Plückthun <phil@kitten.sh>

* Update .changeset/fluffy-guests-begin.md

Co-authored-by: Andy Richardson <andy.john.richardson@gmail.com>
Co-authored-by: Phil Plückthun <phil@kitten.sh>

authored by

Jovi De Croock
Andy Richardson
Phil Plückthun
and committed by
GitHub
814fb044 5cf197a5

+36 -12
+6
.changeset/fluffy-guests-begin.md
··· 1 + --- 2 + '@urql/exchange-graphcache': patch 3 + '@urql/core': patch 4 + --- 5 + 6 + Fix `cache-only` operations being forwarded and triggering fetch requests
+10 -10
exchanges/graphcache/src/cacheExchange.ts
··· 305 305 const cacheOps$ = pipe( 306 306 cache$, 307 307 filter(res => res.outcome === 'miss'), 308 - map(res => addCacheOutcome(res.operation, res.outcome)) 308 + map(res => addCacheOutcome(res.operation, res.outcome)), 309 309 ); 310 310 311 311 // Resolve OperationResults that the cache was able to assemble completely and trigger ··· 342 342 // Forward operations that aren't cacheable and rebound operations 343 343 // Also update the cache with any network results 344 344 const result$ = pipe( 345 - forward( 346 - merge([ 347 - pipe( 348 - inputOps$, 349 - filter(op => !isCacheableQuery(op)) 350 - ), 351 - cacheOps$, 352 - ]) 353 - ), 345 + merge([ 346 + pipe( 347 + inputOps$, 348 + filter(op => !isCacheableQuery(op)) 349 + ), 350 + cacheOps$, 351 + ]), 352 + filter(op => op.context.requestPolicy !== 'cache-only'), 353 + forward, 354 354 map(updateCacheWithResult) 355 355 ); 356 356
+2 -2
packages/core/src/client.test.ts
··· 76 76 } 77 77 `, 78 78 { example: 1234 }, 79 - {} 79 + { requestPolicy: 'cache-only' } 80 80 ) 81 81 .toPromise(); 82 82 ··· 87 87 expect(received.operationName).toEqual('query'); 88 88 expect(received.context).toEqual({ 89 89 url: 'https://hostname.com', 90 - requestPolicy: 'cache-and-network', 90 + requestPolicy: 'cache-only', 91 91 fetchOptions: undefined, 92 92 fetch: undefined, 93 93 suspense: false,
+17
packages/core/src/exchanges/cache.test.ts
··· 104 104 }); 105 105 }); 106 106 107 + it('respects cache-only', () => { 108 + const { source: ops$, next, complete } = input; 109 + const exchange = cacheExchange(exchangeArgs)(ops$); 110 + 111 + publish(exchange); 112 + next({ 113 + ...queryOperation, 114 + context: { 115 + ...queryOperation.context, 116 + requestPolicy: 'cache-only', 117 + }, 118 + }); 119 + complete(); 120 + expect(forwardedOperations.length).toBe(0); 121 + expect(reexecuteOperation).not.toBeCalled(); 122 + }); 123 + 107 124 describe('cache hit', () => { 108 125 it('is miss when operation is forwarded', () => { 109 126 const { source: ops$, next, complete } = input;
+1
packages/core/src/exchanges/cache.ts
··· 86 86 ), 87 87 ]), 88 88 map(op => addMetadata(op, { cacheOutcome: 'miss' })), 89 + filter(op => op.operationName !== 'query' || op.context.requestPolicy !== 'cache-only'), 89 90 forward, 90 91 tap(response => { 91 92 if (