According to Apollo GraphQL docs, Apollo Links can go in two directions - client -> server and server -> client:
However, I am not able to find docs or examples regarding links that go from server -> client. My goal is to catch and parse the incoming data that that is going to be stored in cache. This way, I can read a custom parsed data from cache. Is is possible to achieve this?
Apollo Client stores the results of your GraphQL queries in a local, normalized, in-memory cache. This enables Apollo Client to respond almost immediately to queries for already-cached data, without even sending a network request. The Apollo Client cache is highly configurable.
HTTP caches will not caches POST requests, which means GraphQL is simply not cacheable at the HTTP level. However, GET is indeed a valid way to query a GraphQL server over HTTP. This means that caches could indeed cache GraphQL responses.
Generally, when caching data, the intuition is to put information that's fetched remotely into a local store from where it can be retrieved later on. With GraphQL, the naive approach would be to simply put the results of GraphQL queries into the store and simply return them whenever the same query is sent.
When we have access to the cache object we can call cache. data. delete(key) where key is the key that Apollo is using to store the data for a specific item. And the record will be entirely deleted from the cache.
You can found after afterware example here: https://github.com/apollographql/apollo-link/tree/master/packages/apollo-link-http#afterware-data-manipulation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With