Urql: Optimistic updates / Refetching queries after mutations

Created on 25 Mar 2019  路  7Comments  路  Source: FormidableLabs/urql

Thanks for the amazing work so far!

I am using antd Form element, which takes props, then keeps an internal form state. When my form is ready, i submit a mutation. The problem is, this triggers a new render with the initital props, causing the fields to flicker back to the original values until the mutation is complete (http request)

This all makes sense. I guess i need to overwrite the local state immediately?

Most helpful comment

The default cache is document based so it doesn't support optimistic updates as we only know about very specific query and variables combinations.

So from our perspective it makes more Re sense to add this functionality to a normalised cache, like the one that Apollo has.

I'm currently working on a normalised cache for urql and it's not quite ready yet, but you can track it's progress here: https://github.com/kitten/urql-exchange-graphcache

All 7 comments

The default cache is document based so it doesn't support optimistic updates as we only know about very specific query and variables combinations.

So from our perspective it makes more Re sense to add this functionality to a normalised cache, like the one that Apollo has.

I'm currently working on a normalised cache for urql and it's not quite ready yet, but you can track it's progress here: https://github.com/kitten/urql-exchange-graphcache

That sounds great.

I was thinking that there might be a way to override the cache even on the document however - a another argument to the mutation? Im sure you know the limitations however

@tonypee So basically, you're looking for a cacheExchange that maps mutations to queries that should be refetched?

I think that should be a possible option that can be implemented outside of the exchange infrastructure. It could be built into useMutation / <Mutation> but essentially you can trigger executeQuery after a mutation with the publish operator (which subscribes without issuing any callbacks / events) which would then update that query across components.

I'll close this for now as this is completely under the scope of the normalised cache which we'll track separately

@kitten I see the normalized cache is out now so can we do Optimistic updates now?

@deadcoder0904 Hiya 馃憢 Yes, @urql/exchange-graphcache supports everything that you might expect from a normalised cache including optimistic updates https://github.com/FormidableLabs/urql-exchange-graphcache#usage

Thanks, Phil for your work on this. I really love the name "Wonka" for some reason 馃槀

Was this page helpful?
0 / 5 - 0 ratings

Related issues

maxzhuk0v picture maxzhuk0v  路  3Comments

dotansimha picture dotansimha  路  4Comments

kitten picture kitten  路  4Comments

ivosequeros picture ivosequeros  路  5Comments

nicollecastrog picture nicollecastrog  路  3Comments