Build and Deploy a GraphQL API to the Edge with Fauna โ Part 9

1 min read

Grafbase provides support for edge caching, a feature that enhances performance by serving already cached data, thereby eliminating the need to wait for a response from the database.
Inside grafbase/grafbase.config.ts
we will update the config
export to include a new property: cache
.
export default config({
schema: g,
cache: {
rules: [
{
maxAge: 60,
types: [{ name: 'Query', fields: ['products', 'product'] }],
mutationInvalidation: 'entity'
}
]
}
})
This configuration instructs Grafbase to set a maxAge
to 60
seconds on the queries products
and product
.
The mutationInvalidation
property also tells Grafbase to delete any cached data the entities returned tagged with their id
value. This means if a Product
is mutated and id
matches any cached data tag, the data will be invalidated
๐ก
Caching is a production feature and will not work using the CLI.
0
Subscribe to my newsletter
Read articles from Jamie Barton directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
