Skip to content

[response-cache] - Mark fields as cacheable via directive #1200

Answered by n1ru4l
klausXR asked this question in Q&A
Discussion options

You must be logged in to vote

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),
})

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@n1ru4l
Comment options

@klausXR
Comment options

@n1ru4l
Comment options

@klausXR
Comment options

@n1ru4l
Comment options

Answer selected by klausXR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants