Unable to Cache -- ApolloServerPluginCacheControl Not Working

Hello Apollo Experts,

I’ve been having issues getting ApolloServerPluginCacheControl to work correctly. I have added it from the apollo-server-core package and setup like so:

const server = new ApolloServer({
...,
plugins: [
      ApolloServerPluginDrainHttpServer({ httpServer }),
      {
        async serverWillStart() {
          return {
            async drainServer() {
              subscriptionServer.close();
            },
          };
        },
      },

      responseCachePlugin({
        sessionId: (requestContext) => {
          const user = requestContext.context.user;
          return user ? user.id : null;
        },
      }),
      ApolloServerPluginCacheControl({ defaultMaxAge: 360, calculateHttpHeaders: true }),
})

I’m using like so in my resolver:

user: {
      type: UserType,
      resolve: (message, args, _, info) => {
        if (info && info.cacheControl) {
          info.cacheControl.setCacheHint({ maxAge: 3600 * 1000 * 24, scope: "PRIVATE" });
        }
        console.log({ info__2: info.cacheHint }); // returns undefined

        return message.getUser({ attributes: ["id", "name", "image_url", "last_seen"] });
      },
    }

What I found is, after an initial request in the playground, it throws this exception

"errors": [ { "message": "overallCachePolicy.policyIfCacheable is not a function", "extensions": { "code": "INTERNAL_SERVER_ERROR", "exception": { "stacktrace": [ "TypeError: overallCachePolicy.policyIfCacheable is not a function", " at Object.willSendResponse (/usr/src/app/node_modules/apollo-server-core/src/plugin/cacheControl/index.ts:237:56)", " at /usr/src/app/node_modules/apollo-server-core/src/utils/dispatcher.ts:20:23", " at Array.map (<anonymous>)", " at Dispatcher.callTargets (/usr/src/app/node_modules/apollo-server-core/src/utils/dispatcher.ts:17:25)",

Hey @bwoodlt, can you provide a reproduction that I can clone and run locally to see the error myself? It’s hard to help without more at my disposal.

I do see one error in this line, but that isn’t your actual issue:

console.log({ info__2: info.cacheHint }); // returns undefined

info.cacheHintinfo.cacheControl.cacheHint