Disable cache in ApolloServer when using RESTDataSource
See original GitHub issueI am using RESTDataSource to fetch data from REST api’s but data is being cached.
How to disable cache since data keeps changing in thequery resolver.
Below is the node.js code.
const app = express();
const server = new ApolloServer({
schema: schema,
context: ({ req }) => ({
token: req.headers.authorization,
}),
dataSources: () => apiDataSources,
});
server.applyMiddleware({ app });
app.listen({ port: 4000 }, () => {
console.log("Server is at http://localhost:4000/graphql");
});
Issue Analytics
- State:
- Created 5 years ago
- Comments:33 (4 by maintainers)
Top Results From Across the Web
Server-side caching - Apollo GraphQL Docs
When Apollo Server resolves an operation, it calculates the result's correct cache behavior based on the most restrictive settings among the result's fields ......
Read more >How to invalidate cache in Apollo Server RESTDataSource
It seems like the best solution I can find, is to just leave the HTTP cache layer alone, and use a separate cache...
Read more >Demystify apollo datasource cache | by Ron Liu - Medium
This article is trying to demystify this question. When we develop graphql server using apollo server with REST api as the backend, we...
Read more >How Apollo REST Data Source Deduplicates and Caches API ...
How you can use the apollo-server-caching library to implement your own caching logic. Resolving data from a RESTful API. If you're thinking ...
Read more >Frequently Asked Questions - Apollo GraphQL Docs
The RESTDataSource is a tool that integrates with apollo-server to ... On the client, caches can prevent multiple queries from being called when...
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
In my case, the issue was not the cache of the RESTDataSource class but a wrong initialization of the
dataSources
inside thenew ApolloServer
call:This was wrong because the
dataSources
variable was created once, when the ApolloServer started, so the cache was common to all the requests and not only per one request.The solution for me was to initialize a new dataSources like written inside the doc
Hope this will help someone 😃
It’s important to remove the cache for error responses as well, otherwise you will experience unexpected results.