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.

add example of using inspectFields to invalidate a list (#922)

authored by

Jovi De Croock and committed by
GitHub
3a69fe4b 7c223150

+21
+21
docs/graphcache/custom-updates.md
··· 216 216 }); 217 217 ``` 218 218 219 + Let's combine the above example with invalidating fields, imagine the scenario where we add a todo but 220 + rather than manually pushing it on all the lists we just want to refetch the lists. 221 + 222 + ```js 223 + const cache = cacheExchange({ 224 + updates: { 225 + Mutation: { 226 + addTodo: (result, args, cache, info) => { 227 + const todoQueries = cache.inspectFields('Query').filter(x => x.fieldName === 'todos'); 228 + 229 + todosQueries.forEach(({ fieldName, arguments: variables }) => { 230 + cache.invalidate('Query', fieldName, variables); 231 + }); 232 + }, 233 + }, 234 + }, 235 + }); 236 + ``` 237 + 238 + Now when we come onto a list we'll know that this list needs to be refetched. 239 + 219 240 ## Optimistic updates 220 241 221 242 If we know what result a mutation may return, why wait for the GraphQL API to fulfill our mutations?