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 a specific key for policy options

simone-sanfratello opened this issue · comments

at the moment, the definition for policy options is

  policy: {
    Query: {
      welcome: {
        ttl: 5
      }
    }
  }

this could lead to potential conflicts if there are nested entities with the same name of policy options (ttl, skip, storage and so on), for example

  policy: {
    Query: {
      welcome: {
        ttl: {
           ttl: 1,
           skip: () { /* .. */ }
        }
      }
    }
  }

the proposed solution would be to support the current configuration and introducing a specific key, for example '__options', to be used in case of conflicts, as follow

  policy: {
    Query: {
      welcome: {
        // no __options key present, so policy options are considered as it is
        ttl: 6
      },
      hello: {
        // since "hello" query has a ttl property
        __options: {
          ttl: 6
        },
        ttl: {
          // here we can use both __options or list policy options
          skip: () { /* .. */ }
        }
      }
    }
  }

also, adding validation for nested policies here https://github.com/mercurius-js/cache/blob/main/lib/validation.js#L82

cc @codeflyer

@simone-sanfratello Thanks for bringing this up, I'll look into it