Caching Policies & Derived Queries #272
Description
It would be great if apollo-link-state could declare that some or all of its resolvers need to bypass "cache-only"
. If you want to have your link-state queries use live data, and merge it with remote data that you want to minimize fetching, it's pretty easy to get stuck splitting your code into multiple query components with different fetchPolicies, or over-fetching for no User-interface reason.
When using apollo-link-state, it's pretty natural to want to abstract complex processes, for example: a sequence of network requests that have to occur sequentially to assemble data for another request.
Example
In our app we abstracted away a wizard flow, so that each phase in the wizard can get all the data they need with a simple identifier. -- In this case, using an ID for that drafted form + an ID for the field that the wizard is populating. The problem is that if we leave the Query marked as cache-and-network
, sometimes Apollo chooses not to hit our link-state resolver.
(In my case we're also using apollo-link-rest under the hood, but I don't think this affects the problem).
Ideas
A. Add an API where any resolver can be marked with an overriding cache-policy for that segment of the response.
B. Add an API where resolvers can return overriding cache-policies for data that is returned
C. Add an API where resolvers return a "parameter-checksum" that can override the logic used for query-lookup in the cache. -- In my example case, the parameters to my field-lookup API are: draftId
& fieldId
, but the underlying Queries that were used received more parameters. -- I could have collated those underlying parameters, and used them to build this checksum instead of draftId
& fieldId
D. Change the resolver api so link-state resolvers always call their underlying implementations, passing them cache-data, but provide them the fetchPolicy so they can choose to return the cached data, or override it.
Technically, some of the changes for this feature-request may need to be done in apollo-link or apollo-client, but this link is the one that might be invested in driving these features forwards.