Is your feature request related to a problem? Please describe.
In Apollo, the client allows you to easily update the cache after a mutation using an update function.
Describe the solution you'd like
A new Mutation object should have accept an update function as a parameter. That update function should include the cache and the data returned from the mutation as parameters. Take the following example:
_updateCacheAfterCreate(cache, result) {
var data = cache.readQuery(query: feedQuery);
data.feed.links.add(result.link);
cache.writeQuery(query: feedQuery, data: data);
}
The query runs against the local cache and is then updated with the link result from the mutation using the writeQuery function. This function is passed to Mutation as follows:
Mutation(
voteMutation,
update:_updateCacheAfterCreate,
)
Describe alternatives you've considered
Currently, the UI updates using polling.
Additional context
https://www.howtographql.com/react-apollo/6-more-mutations-and-updating-the-store/
@chimon2000 Yeah this is a high priority one for us internally. Will be programmed after the new link system.
This was implemented in #130 - example usage
And will be even more useful/usable after #199
what do I pass in as the key to reading cache?
@serendipity1004 that depends on what you're trying to read. Operations have a .toKey() method that is used for getting the cache key, but if you're getting the current value of a normalized entity then you just need the result of your dataIdFromObject
This was implemented in #130 - example usage
And will be even more useful/usable after #199
Broken example link
@kevinrodriguez-io example usage.
Most helpful comment
@chimon2000 Yeah this is a high priority one for us internally. Will be programmed after the new link system.