GraphQL Edge Caching Scopes

Hugo BarrigasHugo BarrigasJamie BartonJamie Barton
GraphQL Edge Caching Scopes

GraphQL Edge Caching gives you the power to improve performance of any GraphQL or REST API, as well as queries to MongoDB Atlas with its expanding set of connectors.

We're excited to announce the latest improvement to GraphQL Edge Caching: Scopes!

Imagine your cache as a library. By default, any book (cached entry) is only accessible to one person at a time (request auth). But what if multiple people want the same read the same exact book?

Instead of reserving many identical books, we have a shared section for popular books. This shared section is what we call "scopes".

Scopes let you mark certain data as "shared," so different users can access it. It's a way to efficiently serve common data to multiple users.

The new scopes feature allows the following access (auth) options:

apikeyUses the request api key operations as part of the cache key.
{header: "value"}Uses the request header value as part of the cache key.
{claim: "value"}Uses the request jwt claim value as part of the cache key
publicUses the allowed_public_ops operations via auth.

Here's how easy it is to get started using the Grafbase Configuration:

import { config, g } from '@grafbase/sdk'

g.model('Post', {
  title: g.string(),
  slug: g.string().unique(),
  content: g.string()
  maxAge: 60,
  scopes: ['apikey']

Please note — if a given request has cache access scopes defined and data to fulfil at least one scope can't be extracted, then the cache will be bypassed altogether.

We'd love to hear your feedback and ideas, so join us on Discord.