Hello, I set up my apollo server as per instructions at “Server-side caching - Apollo GraphQL Docs”
The issue is that my resolver is being hit every time. Am I not understanding something or is not the way it’s supposed to be that server returns cached data and not calls the resolver every time
Here is my code (next.js app)
// route: /api/graphql
const apolloServer = new ApolloServer({
schema: schemaWithResolvers,
introspection: true,
plugins: [
responseCachePlugin({
// cache: new InMemoryLRUCache({}),
sessionId: (requestContext) => {
const cookie = requestContext.request.http.headers.get("cookie");
if (cookie) {
const index = cookie.indexOf("next-auth.session-token=");
if (index > -1) {
return cookie.substring(index + 24, index + 24 + 64) as Any;
}
}
return null;
},
}),
],
});
export default startServerAndCreateNextHandler(apolloServer, {
context: async (req, res) => {
return createServerContext(req, res, db);
},
});
And this is the resolver
Query: {
async schedule(_, { id }: any, context, info) {
console.log("IS HIT"); // <--- this is hit on every page load, WHY?
info.cacheControl.setCacheHint({ maxAge: 6000, scope: "PRIVATE" });
return context.db.schedules.schedule(id, context);
},
}