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): ignore current entity during invalidateType (#3560)

authored by

Jovi De Croock and committed by
GitHub
52b42270 0b9a52a9

+23 -5
+5
.changeset/rich-suns-sit.md
··· 1 + --- 2 + '@urql/exchange-graphcache': patch 3 + --- 4 + 5 + When invoking the automatic creation updater ignore the entity we are currently on in the mutation
+6
exchanges/graphcache/src/cacheExchange.test.ts
··· 1927 1927 vi.runAllTimers(); 1928 1928 expect(response).toHaveBeenCalledTimes(3); 1929 1929 expect(result).toHaveBeenCalledTimes(3); 1930 + expect(result.mock.calls[1][0].data).toEqual({ 1931 + addAuthor: { 1932 + id: '2', 1933 + name: 'Author 2', 1934 + }, 1935 + }); 1930 1936 }); 1931 1937 }); 1932 1938
+5 -1
exchanges/graphcache/src/operations/invalidate.ts
··· 25 25 } 26 26 }; 27 27 28 - export const invalidateType = (typename: string) => { 28 + export const invalidateType = ( 29 + typename: string, 30 + excludedEntities: string[] 31 + ) => { 29 32 const types = InMemoryData.getEntitiesForType(typename); 30 33 for (const entity of types) { 34 + if (excludedEntities.includes(entity)) continue; 31 35 invalidateEntity(entity); 32 36 } 33 37 };
+6 -3
exchanges/graphcache/src/operations/write.ts
··· 383 383 // if we don't we'll assume this is a create mutation and invalidate 384 384 // the found __typename. 385 385 if (fieldValue && Array.isArray(fieldValue)) { 386 + const excludedEntities: string[] = fieldValue.map( 387 + entity => ctx.store.keyOfEntity(entity) || '' 388 + ); 386 389 for (let i = 0, l = fieldValue.length; i < l; i++) { 387 - const key = ctx.store.keyOfEntity(fieldValue[i]); 390 + const key = excludedEntities[i]; 388 391 if (key && fieldValue[i].__typename) { 389 392 const resolved = InMemoryData.readRecord(key, '__typename'); 390 393 const count = InMemoryData!.getRefCount(key); 391 394 if (resolved && !count) { 392 - invalidateType(fieldValue[i].__typename); 395 + invalidateType(fieldValue[i].__typename, excludedEntities); 393 396 } 394 397 } 395 398 } ··· 399 402 const resolved = InMemoryData.readRecord(key, '__typename'); 400 403 const count = InMemoryData.getRefCount(key); 401 404 if ((!resolved || !count) && fieldValue.__typename) { 402 - invalidateType(fieldValue.__typename); 405 + invalidateType(fieldValue.__typename, [key]); 403 406 } 404 407 } 405 408 }
+1 -1
exchanges/graphcache/src/store/store.ts
··· 174 174 !this.resolve(entity, '__typename'); 175 175 176 176 if (shouldInvalidateType) { 177 - invalidateType(entity); 177 + invalidateType(entity, []); 178 178 } else { 179 179 invariant( 180 180 entityKey,