Caching does not seem to work with apollo-server-micro in ApolloGraphql server

Viewed 133

I'm following a simple example with NextJS running an Apollo GraphQL server with the package apollo-server-micro. I basically have this:

import { ApolloServer, makeExecutableSchema,  } from "apollo-server-micro";
import responseCachePlugin from 'apollo-server-plugin-response-cache';

const typeDefs = require("../../apolloserver/schema");
const { Query } = require("../../apolloserver/resolvers");

const resolvers = {
  Query
};

const schema = makeExecutableSchema({ typeDefs, resolvers });

const apolloServer = new ApolloServer({
  schema,
  context(ctx) {
    return {...ctx,prisma};
  },
  resolvers,
  plugins: [responseCachePlugin()]
});

export const config = {
  api: {
    bodyParser: false,
  },
};

export default apolloServer.createHandler({ path: "/api/graphql" });

And when I add the Cache Control to my resolver as follows, I get an error saying

Cannot read property 'cacheControl' of undefined
async function codeCampYears(parent: any, args: any, context: any, info: any) {

  console.log(`[${new Date().toLocaleTimeString()}] Query.MyTable`);
  info.cacheControl.setCacheHint({ maxAge: 10 });

  const data = await context.prisma.MyTable.findMany();
0 Answers
Related