apollo-server-plugin-response-cache: cache hint not working
See original GitHub issueMy apollo graphql server setup uses the following:
"apollo-datasource-rest": "^0.6.9",
"apollo-server-express": "^2.9.12",
"apollo-server-plugin-response-cache": "^0.3.8",
My schema:
type Query {
types: [Type!]! @cacheControl(maxAge: 3600)
}
type Type {
id: ID!
label: String!
active: Boolean!
}
My responseCachePlugin config:
responseCachePlugin({
sessionId: (requestContext) => (requestContext.request.http.headers.get('sessionId') || null),
})
Neither the static cache hint like the above nor the dynamic cache hint in the resolver work. i.e., they don’t cache the response from the datasource (REST API).
A bunch of other devs reported this issue on Spectrum. One of the Spectrum posts points to the problem:
The property requestContext.overallCachePolicy doesn't get updated by the cache hint, nither the static one in schema or the dynamic one ...
The value is always the cacheControl you configured when creating ApolloServer
github link to the line in the code where there is a potential problem: https://github.com/apollographql/apollo-server/blob/1acf62d903253f5669c0c4f7255c8a87b95b5e6c/packages/apollo-server-plugin-response-cache/src/ApolloServerPluginResponseCache.ts#L243
Spectrum post that details the above issue: https://spectrum.chat/apollo/apollo-server/apollo-server-plugin-response-cache-is-not-working-properly~e3390cd4-9e3f-4919-88b4-92508e235e38
Other Spectrum posts that talk about this problem:
- https://spectrum.chat/apollo/apollo-server/cachecontrol-does-not-work-unless-defaultmaxage-is-set~0e4dc3c5-7cdc-40be-b833-0b2d436d1288
- https://spectrum.chat/apollo/apollo-server/does-rediscache-work-in-dev-mode~18358268-8d11-4b13-a0c9-abddfb6623f3
cc to: @trevor-scheer
Issue Analytics
- State:
- Created 4 years ago
- Reactions:37
- Comments:64 (17 by maintainers)
Top Results From Across the Web
Server-side caching - Apollo GraphQL Docs
Our philosophy behind Apollo Server caching is that a response should only be considered cacheable if every part of that response opts in...
Read more >API Reference: Cache control plugin - Apollo GraphQL Docs
This plugin enables your GraphQL server to specify a cache policy at the field level, either statically in your schema with the @cacheControl...
Read more >Server-side caching - Apollo GraphQL Docs
You can cache Apollo Server query responses in stores like Redis, Memcached, or Apollo Server's in-memory cache. In-memory cache setup. To set up...
Read more >responseCachePlugin() is not a function - Apollo Community
Hi, I am trying to learn GraphQL and how to use the server side caching but when I import responseCachePlugin and add it...
Read more >Automatic persisted queries - Apollo GraphQL Docs
A persisted query is a query string that's cached on the server side, ... thus reducing request sizes dramatically (response sizes are unaffected)....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It’s disappointing the cache only works if you set a global caching settings:
I am using
merge-graphql-schemas
with Redis and I am unable to get anything cached without the global settings.I think it is a great idea to
@cacheControl
in the schema but it would be even better it it works first.It is documented correctly but the result is not something usable. If you can’t set a overall cache, the cache doesn’t work at all. This is basically the issue. I wonder if someone from Apollo actively looks at the issues?