Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimistic updates / Refetching queries after mutations #212

Closed
tonypee opened this issue Mar 25, 2019 · 7 comments
Closed

Optimistic updates / Refetching queries after mutations #212

tonypee opened this issue Mar 25, 2019 · 7 comments

Comments

@tonypee
Copy link

tonypee commented Mar 25, 2019

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?

@kitten
Copy link
Member

kitten commented Mar 25, 2019

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

@tonypee
Copy link
Author

tonypee commented Mar 25, 2019

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

@kitten
Copy link
Member

kitten commented Mar 28, 2019

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

@kitten kitten changed the title optimistic updates Optimistic updates / Refetching queries after mutations Mar 28, 2019
@kitten
Copy link
Member

kitten commented Jun 13, 2019

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

@kitten kitten closed this as completed Jun 13, 2019
@deadcoder0904
Copy link

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

@kitten
Copy link
Member

kitten commented Oct 9, 2019

@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

@deadcoder0904
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants