Clarification on Handling Multiple Mutations with the Same Mutation Key in Offline-First App #7466
Unanswered
jahirfiquitiva
asked this question in
Q&A
Replies: 1 comment
-
yes. order of resuming is guaranteed to be the same as how they were executed, however, all mutations will run in parallel (as they also would when you are online). If you want them to run in serial, you need scoped mutations: https://tanstack.com/query/latest/docs/framework/react/guides/mutations#mutation-scopes |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
We're creating an app that works offline-first.
We're defining default mutations for our app, each with a default mutation key.
Let's say we have
tasks, and we have thecreate,updateanddeletemutations.So, we would have 3 default mutations each one with one of the following mutation keys:
['tasks', 'create']['tasks', 'update']['tasks', 'delete']Now, let's say our user is offline, and does this:
1and2existed3wascreated1content isupdated2content isupdated3content isupdated2content isupdated again1isdeletedQuestion 1:
Is TanStack Query able to identify the 4 update mutations independently (separating one from the other), and resuming each when the user is back online, even though they all have the same
mutationKey(['tasks', 'update'])?Question 2: (If question 1 answer is no)
Would it be required, then, that we add the task id to the mutation key to help TanStack Query identify them?
Something like:
Is there a better approach to this?
Question 3:
Will the second
updatemutation on task2overwrite its first mutation, meaning the first mutation would not be executed when the user is back online?I personally think that given this explanation for what the
mutationKeyis for, and since it's optional, we probably do not need to set a uniquemutationKeyfor every mutation and that they would be resumed normally.And also because when we use/do
queryClient.getMutationCache(), even if we filter mutations with a givenmutationKey(let's say['tasks', 'update']) each mutation has a uniquemutationIdeven if there's multiple mutations with the samemutationKeyThanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions