mercurius-js / cache

Adds an in-process caching layer to Mercurius. Federation is fully supported.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

add `policy.key` option

simone-sanfratello opened this issue · comments

add option to define a custom serialize function for any policy, or one for all, for example

const schema = `
  type Query {
    add(x: Int, y: Int): Int
  }
`
// ...

app.register(cache, {
  ttl: 10,
  policy: {
    Query: {
      add: { 
        key: ({ fields, self, args, info, context }) => `x:${args.x}-y:${args.y}`
    }
  }
})

note: extendKey option is ignored, should be thrown an error on policy validation if key and extendKey are both used