i have graphql with apollo-server-hapi. i try to add cache control like below:
const graphqlOptions = {
schema,
tracing: true,
cacheControl: true,
};
but when i try to add cache option on schema base:
type Author @cacheControl(maxAge: 60) {
id: Int
firstName: String
lastName: String
posts: [Post]
}
i got this error message:
Error: Unknown directive "cacheControl".
can you help, what is the correct way to apply cache control on schema?
i follow instruction from below, but it seem didn't work.
apollo-cache-control
After learn more about caching on apollo graphql, basically, the issue was with makeExecutableSchema from apollo-server-hapi, didn't include directive for @cacheControl, so to make it work, we just need to define our own @cacheControl directive into graphql file, as below:
enum CacheControlScope {
PUBLIC
PRIVATE
}
directive @cacheControl (
maxAge: Int
scope: CacheControlScope
) on FIELD_DEFINITION | OBJECT | INTERFACE
type Author @cacheControl(maxAge: 60) {
id: Int
firstName: String
lastName: String
posts: [Post]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With