Invalidating Lists
Let's say you have a Todo type, a Query.todos
query, and a Mutation.addTodo
mutation in your GraphQL API
type Todo {
id: ID!
# ...
}
type Query {
todos: [Todo!]!
# ...
}
type Mutation {
addTodo(...): Todo
}
When the addTodo
mutation passes through Stellate, it returns a new todo.
{
"data": {
"addTodo": {
"id": "5"
}
}
}
Depending on your setting for mutation policies the Automatic Cache Invalidation might not invalidate the Query.todos
query automatically, as it doesn't know which list that todo was added to.
You have multiple ways to ensure the stale cached query results are invalidated correctly by manually purging data via the Purging API from your backend:
-
Setting your mutation policies to either
List
or evenType
. -
Invalidate all responses that contain
Todo
s, even if they haven't been changed by callingpurgeTodo
without any arguments.mutation { _purgeTodo() }
-
Purge all queries that request the
todos
field using the_purgeQuery
mutationmutation { _purgeQuery(queries: [todos]) }
-
Add an operation name to your query (e.g.
query getTodos { todos { ... } }
) and purge any cached result of that query by its namemutation { _purgeOperationName(names: ["getTodos"]) }
-
Determining one of the
Todo
s that was previously on the list and purging that specificallymutation { purgeTodo(id: "idOfLatestTodoAlreadyInTheList") }