Key Fields

In order to know which fields identify individual resources in your schema Stellate needs to know which field holds the unique identifier for a certain node type. This is mainly used for purging changed results from the cache, either via automatic cache invalidation or the Purging API

By default, Stellate looks for id and key fields on your types. However, sometimes you have other unique fields (like e.g. User.email) that you want to use for this purpose.

To tell the Stellate Edge Cache that email is a field that uniquely identifies resources, go to the Key Fields settings of your service. You will see the default key fields that Stellate assigned automatically and can configure your custom fields as well.

Key fields are also configurable via the Stellate configuration file. The config exposes a key called keyFields that can be used like so:

import { Config } from 'stellate'

const config: Config = {
  config: {
    keyFields: {
      types: {
        NewsLetterSubscriber: ['id', 'email'],
      },
    },
  },
}
export default config

These key fields are then immediately exposed and purgeable via the purging API:

# Purge newsletter subscriber with the email max@stellate.co
mutation {
  purgeNewsletterSubscriber(email: ["max@stellate.co"])
}

For more information about cache purging and the purging API read the documentation on the Purging API.