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
,update
anddelete
mutations.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:
1
and2
existed3
wascreate
d1
content isupdate
d2
content isupdate
d3
content isupdate
d2
content isupdate
d again1
isdelete
dQuestion 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
update
mutation on task2
overwrite 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
mutationKey
is for, and since it's optional, we probably do not need to set a uniquemutationKey
for 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 uniquemutationId
even if there's multiple mutations with the samemutationKey
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions