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(persisted): Add dev warning for persisted-miss results for an already persisted-miss errored operation (repeated retries) (#3442)

authored by

Phil Pluckthun and committed by
GitHub
f7684a0a 8ff4e3e4

+51
+5
.changeset/late-plants-poke.md
··· 1 + --- 2 + '@urql/exchange-persisted': patch 3 + --- 4 + 5 + Warn about cached persisted-miss results in development, when a `persistedExchange()` sees a persisted-miss error for a result that's already seen a persisted-miss error (i.e. two misses). This shouldn't happen unless something is caching persisted errors and we should warn about this appropriately.
+34
exchanges/persisted/src/persistedExchange.test.ts
··· 119 119 expect(operations[2].extensions).toEqual(undefined); 120 120 }); 121 121 122 + it('fails gracefully when an invalid result with `PersistedQueryNotFound` is always delivered', async () => { 123 + const { result, operations, exchangeArgs } = makeExchangeArgs(); 124 + 125 + result.mockImplementation(operation => ({ 126 + ...queryResponse, 127 + operation, 128 + error: new CombinedError({ 129 + graphQLErrors: [{ message: 'PersistedQueryNotFound' }], 130 + }), 131 + })); 132 + 133 + const res = await pipe( 134 + fromValue(queryOperation), 135 + persistedExchange()(exchangeArgs), 136 + take(1), 137 + toPromise 138 + ); 139 + 140 + expect(res.operation.context.persistAttempt).toBe(true); 141 + expect(operations.length).toBe(2); 142 + 143 + expect(operations[1].extensions).toEqual({ 144 + persistedQuery: { 145 + version: 1, 146 + sha256Hash: expect.any(String), 147 + miss: true, 148 + }, 149 + }); 150 + 151 + expect(console.warn).toHaveBeenLastCalledWith( 152 + expect.stringMatching(/two misses/i) 153 + ); 154 + }); 155 + 122 156 it('skips operation when generateHash returns a nullish value', async () => { 123 157 const { result, operations, exchangeArgs } = makeExchangeArgs(); 124 158
+12
exchanges/persisted/src/persistedExchange.ts
··· 216 216 retries.next(followupOperation); 217 217 return null; 218 218 } else if (result.error && isPersistedMiss(result.error)) { 219 + if (result.operation.extensions.persistedQuery.miss) { 220 + if (process.env.NODE_ENV !== 'production') { 221 + console.warn( 222 + 'persistedExchange()’s results include two misses for the same operation.\n' + 223 + 'This is not expected as it means a persisted error has been delivered for a non-persisted query!\n' + 224 + 'Another exchange with a cache may be delivering an outdated result. For example, a server-side ssrExchange() may be caching an errored result.\n' + 225 + 'Try moving the persistedExchange() in past these exchanges, for example in front of your fetchExchange.' 226 + ); 227 + } 228 + 229 + return result; 230 + } 219 231 // Update operation with unsupported attempt 220 232 const followupOperation = makeOperation( 221 233 result.operation.kind,