On server
apollo-server-caching
On client
Following this strategy, Apollo will be forced to refetch certain queries if the user re-requests them, but won’t trigger potentially hundreds of requests just because a user might re-request them later. And this allows us to leave the default fetchPolicy
in place so that we can benefit from caching when the user is not adding data via mutations.
useMutation(CREATE_TASK, {
update: cache => {
cache.evict({
id: "ROOT_QUERY",
field: "tasks"
})
}
}
This code assumes we want to flush out any responses to any queries that are cached via the tasks
key but we can also be more targeted if we like.
useMutation(CREATE_TASK, {
update: (cache, mutationResult) => {
const newTask = mutationResult.data.createTask;
cache.evict({
id: "ROOT_QUERY",
field: "tasks",
args: { name: newTask.name }
})
}
})
Comments
Post a Comment