Graphql-flutter: Update cache after mutation

Created on 15 Aug 2018  路  6Comments  路  Source: zino-app/graphql-flutter

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/

enhancement next

Most helpful comment

@chimon2000 Yeah this is a high priority one for us internally. Will be programmed after the new link system.

All 6 comments

@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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mainawycliffe picture mainawycliffe  路  16Comments

juicycleff picture juicycleff  路  50Comments

chimon2000 picture chimon2000  路  24Comments

diegothucao picture diegothucao  路  21Comments

Wisdom0063 picture Wisdom0063  路  26Comments