mercurius-js / cache

Adds an in-process caching layer to Mercurius. Federation is fully supported.
MIT License
106 stars 19 forks source link

add `policy.key` option #86

Closed simone-sanfratello closed 2 years ago

simone-sanfratello commented 2 years ago

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