January 2019
Intermediate to advanced
460 pages
10h 33m
English
We want to explicitly add only the new post to the cache of the Apollo Client. Using the cache helps us to save data, by not refetching the complete feed or rerendering the complete list. To update the cache, you should remove the refetchQueries property. You can then introduce a new property, called update, as shown in the following code:
<Mutation update = {(store, { data: { addPost } }) => { const data = store.readQuery({ query: GET_POSTS }); data.posts.unshift(addPost); store.writeQuery({ query: GET_POSTS, data }); }}
The new property runs when the GraphQL addPost mutation has finished. The first parameter that it receives is the store of the Apollo Client, in which the whole cache is saved. The second parameter ...
Read now
Unlock full access