-
I would like to add a custom directive, like When a query comes, after it is parsed, I would like to verify that the types queried by the client are all marked as cacheable ( cache opt-in ), if so, the cache should be enabled, else - disabled. How should I implement such feature with the |
Beta Was this translation helpful? Give feedback.
Answered by
n1ru4l
Jan 14, 2022
Replies: 1 comment 6 replies
-
You can use an AST visitor for building the configuration (https://graphql.org/graphql-js/language/#visit). Pseudo Code: import { visit} from "graphql"
function buildResponseTTLCacheConfig(schemaAST) {
const config = {
ttlPerSchemaCoordinate: {}
}
visit(schemaAST, {
Directive(node) {
// check if directive is Cacheable and whether it is applied on a field...
ttl[ttlPerSchemaCoordinate][name] = ???
}
})
return ttl
}
useResponseCache({
...buildResponseTTLCacheConfig(schemaAST),
}) |
Beta Was this translation helpful? Give feedback.
6 replies
Answer selected by
klausXR
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use an AST visitor for building the configuration (https://graphql.org/graphql-js/language/#visit).
Pseudo Code: