Skip to content

apollo-server-plugin-response-cache: shouldReadFromCache and shouldWriteToCache are declared as returning ValueOrPromise but never await #4886

@u007

Description

@u007

my sample code uses strapi:

module.exports = {
  "endpoint": "/graphql",
  "shadowCRUD": true,
  "playgroundAlways": false,
  "depthLimit": 7,
  "amountLimit": 200,
  "shareEnabled": false,
  federation: false,
  apolloServer: {
    tracing: 'production' !== strapi.config.environment ? true : false,
    // persistedQueries: { ttl: 10 * MAX_AGE }, // we set this to be a factor of 10, somewhat arbitrary
    // cacheControl: { defaultMaxAge: MAX_AGE },
    plugins: [
      apolloServerPluginResponseCache({
        shouldReadFromCache,
        shouldWriteToCache,
        extraCacheKeyData,
        sessionId,
      }),
      injectCacheControl()
    ]
  },
  redisCacheClient: cache
}

// does not work all the time
async function shouldReadFromCache(requestContext) {
  if ('IntrospectionQuery' == requestContext.operationName) return false;// graphql ping ignore
  // return true;
  if (cacheQueryNames.includes(requestContext.operationName)) {
    const expired = await cacheExpired(requestContext);
    console.debug("shouldReadFromCache:", requestContext.operationName, 'expired?', expired);
    return !expired;
  }
  console.debug("readCache nocache:", requestContext.operationName);
  return false;
}


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions