apollographql / apollo-client

:rocket:  A fully-featured, production ready caching GraphQL client for every UI framework and GraphQL server.
https://apollographql.com/client
MIT License
19.29k stars 2.64k forks source link

useMutation does not immediately update the cache with result when provided with refetchQueries #11044

Open prscoelho opened 1 year ago

prscoelho commented 1 year ago

Issue Description

My use case is to update the cache with the result from mutation and also refresh a query to get the side effects of the mutation, but this second step can happen without showing anything the user, while the result of the mutation is shown to the user.

When I don't provide refetchQueries, it updates the cache as expected with the result from mutation. When I pass it the refetchQueries, it waits until the refetchQueries completes to update anything.

If the refetchQueries contains queries which don't "conflict" with the mutation data, the cache is immediately updated.

Link to Reproduction

https://github.com/prscoelho/mutation-cache-update

Reproduction Steps

I have added the following delays in the repro:

When clicking on the button, it stops loading after 500ms but only updates data after 2 seconds.

By commenting out the refetchQueries option, you can verify that the data is updated after 500ms.

I've also added a separate query that doesn't contain mutation data, and when I only list that one in the refetchQueries, it updates the cache immediately. (needs to be changed in the code, App.tsx lines 48-49)

forrestwilkins commented 1 month ago

I'm also dealing with this issue and am on version ^3.8.3. Were you ever able to resolve the issue?