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
, _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, Key Fields can be defined in the Stellate configuration file.
The keyFields
field 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.
Changing default key-fields
By default we’ll check for keys at id
, _id
and key
on your responses, however sometimes you might need
to change this when you use something along the lines of idx
, if that’s the case you can add the following
config
import { Config } from 'stellate'
const config: Config = {
config: {
keyFields: {
defaults: ['idx', 'id', '_id', 'key'],
types: {},
},
},
}
export default config
this will add your own custom identifier to the surrogate-keys.