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): backport invalidation fix (#3545)

authored by

Jovi De Croock and committed by
GitHub
6bd4c90f 9405b3d8

+18 -2
+5
.changeset/ninety-taxis-return.md
··· 1 + --- 2 + '@urql/exchange-graphcache': patch 3 + --- 4 + 5 + Fix `invalidate` not applying when using a string to invalidate an entity
+8 -1
exchanges/graphcache/src/store/store.test.ts
··· 856 856 }); 857 857 858 858 describe('Invalidating an entity', () => { 859 - it('removes an entity from a list.', () => { 859 + it('removes an entity from a list by object-key.', () => { 860 860 InMemoryData.initDataState('write', store.data, null); 861 861 store.invalidate(todosData.todos[1]); 862 + const { data } = query(store, { query: Todos }); 863 + expect(data).toBe(null); 864 + }); 865 + 866 + it('removes an entity from a list by string-key.', () => { 867 + InMemoryData.initDataState('write', store.data, null); 868 + store.invalidate(store.keyOfEntity(todosData.todos[1])); 862 869 const { data } = query(store, { query: Todos }); 863 870 expect(data).toBe(null); 864 871 });
+5 -1
exchanges/graphcache/src/store/store.ts
··· 167 167 invalidate(entity: Entity, field?: string, args?: FieldArgs) { 168 168 const entityKey = this.keyOfEntity(entity); 169 169 const shouldInvalidateType = 170 - entity && typeof entity === 'string' && !field && !args; 170 + entity && 171 + typeof entity === 'string' && 172 + !field && 173 + !args && 174 + !this.resolve(entity, '__typename'); 171 175 172 176 if (shouldInvalidateType) { 173 177 invalidateType(entity);