Recently I have been working on GraphQL APIs. Due to the scalability of the project, I want to know if can i cache the response coming from apis.
I know that we can use the query cache and schema cache facility from the lighthouse package. However, my concern is they cache the response during the use of the cache facility in the project.
if we cannot cache the API's response using query cache directives then how can I can do that in my project?
There a multiple levels of caching possible which you can read about in the documentation.
The first is field level caching with the
@cache
directive. This will cache the result of a field in your application cache. You can read about the specifics in the docs. Small excerpt:The other one is a full request/response cache, you can achieve this with a CDN or proxies like Varnish, how to set this up is out of scope but this requires the
Cache-Control
HTTP header to instruct the caching layer if and how it can cache the response. You can read about how to configure this in the docs. Small excerpt: