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(graphcache): Fix `@defer` state carrying over to next operation (#3497)

authored by

Phil Pluckthun and committed by
GitHub
f7b78e2f 87d79cde

+78
+5
.changeset/serious-tables-ring.md
··· 1 + --- 2 + '@urql/exchange-graphcache': patch 3 + --- 4 + 5 + Fix `@defer` state leaking into following operations.
+71
exchanges/graphcache/src/cacheExchange.test.ts
··· 3007 3007 expect(combinedData).toHaveProperty('data.deferred.id', 1); 3008 3008 expect(combinedData).toHaveProperty('data.node.id', 2); 3009 3009 }); 3010 + 3011 + it('applies deferred logic only to deferred operations', () => { 3012 + let failingData: OperationResult | undefined; 3013 + 3014 + const client = createClient({ 3015 + url: 'http://0.0.0.0', 3016 + exchanges: [], 3017 + }); 3018 + 3019 + const { source: ops$, next: nextOp } = makeSubject<Operation>(); 3020 + const { source: res$ } = makeSubject<OperationResult>(); 3021 + 3022 + const deferredQuery = gql` 3023 + { 3024 + ... @defer { 3025 + deferred { 3026 + id 3027 + name 3028 + } 3029 + } 3030 + } 3031 + `; 3032 + 3033 + const failingQuery = gql` 3034 + { 3035 + deferred { 3036 + id 3037 + name 3038 + } 3039 + } 3040 + `; 3041 + 3042 + const forward = (ops$: Source<Operation>): Source<OperationResult> => 3043 + share( 3044 + merge([ 3045 + pipe( 3046 + ops$, 3047 + filter(() => false) 3048 + ) as any, 3049 + res$, 3050 + ]) 3051 + ); 3052 + 3053 + pipe( 3054 + cacheExchange()({ forward, client, dispatchDebug })(ops$), 3055 + tap(result => { 3056 + if (result.operation.kind === 'query') { 3057 + if (result.operation.key === 1) { 3058 + failingData = result; 3059 + } 3060 + } 3061 + }), 3062 + publish 3063 + ); 3064 + 3065 + const failingOp = client.createRequestOperation('query', { 3066 + key: 1, 3067 + query: failingQuery, 3068 + variables: undefined, 3069 + }); 3070 + const deferredOp = client.createRequestOperation('query', { 3071 + key: 2, 3072 + query: deferredQuery, 3073 + variables: undefined, 3074 + }); 3075 + 3076 + nextOp(deferredOp); 3077 + nextOp(failingOp); 3078 + 3079 + expect(failingData).not.toMatchObject({ hasNext: true }); 3080 + }); 3010 3081 });
+2
exchanges/graphcache/src/operations/shared.ts
··· 64 64 entityKey: string, 65 65 error: CombinedError | undefined 66 66 ): Context => { 67 + deferRef = false; 68 + 67 69 const ctx: Context = { 68 70 store, 69 71 variables,