-
-
Notifications
You must be signed in to change notification settings - Fork 626
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
mutations through watchQuery use cacheAndNetwork, which yields unexpected results #774
Comments
To illustrate the issues further: Mutation results are cached (more or less) under Lets say we have a mutation, mutate createOrder($placeId: ID!){
createOrder(placeId: $placeId) { ...orderFields }
} It is called once, then that order is mutated later, but the results of the mutation are still used in the UI as a list item. That mutation sits in the cache like so: {
"Mutation": {
"__typename": "Mutation",
"createOrder({\"data\":{\"placeId\":\"bar-3-aaaa-aaaa-aaaa-aaaaaaaaaaaa\"}})": {
"$ref": "Order:old-closed-order-bbbb-bbbb-bbbb-bbbbbbbbbbbb"
}
}
} If a new mutation is made to create a fresh order:
A potential workaround for now is to use a differentiating variable. Will have to think/investigate more. |
This might require some significant refactoring. In apollo, The quickest way for us to solve this IMO is to add a |
Maybe add other general constraints and errors around the mutation code path, as it allows for other jank like #792 (comment) |
🎉 This issue has been resolved in version 4.0.0-beta.7 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
🎉 This issue has been resolved in version 4.0.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
the default fetch policy for
client.mutate
isnetworkOnly
, because it is usually the case that the fields requested correspond to mutated data, and thus are expected to be stale if fetched eagerly from the cache.However, when a mutation is made with
client.watchQuery
(such as with theMutation
widget), thecacheAndNetwork
policy is used by default, resulting in unexpectedly stale data when anoptimisticResult
is not provided.Another serious issue is that the same mutation, with the same variables, might return different entities. If those results are used in parts of the application, the results of the latest usage will overwrite those of the older ones.
The text was updated successfully, but these errors were encountered: