Automatic Cache Invalidation via Mutations

While GraphCDN offers a powerful Purging API, that allows you fine-grained control over which items are purged from the cache as well as when we also wanted our users to not have to think about purging most of the time.

That's why we implemented a feature that automatically invalidates any cached query results based on the responses to your mutations.

For example, imagine this GraphQL schema:

type Post {
  id: ID!
  author: User!
  comments: [Comment!]!
}

type Mutation {
  updatePost: Post!
}

mutation {   
  updatePost {
    id
    comments {
      id
    }
    author {
      id
    }
  }
}

Once the mutation completes, any query result that contains the Post with the returned ID and any query result that contains the User with the returned ID (at Post.author) and any query result that contains any of the comments with the returned IDs (at Post.comments[n].id) will fully automatically be invalidated.

Edge cases

The most common case where automatic mutation invalidation does not automatically invalidate data is when items are added to a list. You can learn more about how to manually purge in that case in How-to invalidate lists!


Did this page help you?