-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
fix(vue-query): Make use mutate reactive to argument changes #4339
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
fix(vue-query): Make use mutate reactive to argument changes #4339
Conversation
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 830ecfc:
|
|
So, from my point of view, there are a lot of unnecessary changes. // A Vue version of MutationObserverOptions from "@tanstack/query-core"
// Accept refs as options
export type VueMutationObserverOptions<
TData = unknown,
TError = unknown,
TVariables = void,
TContext = unknown,
> = {
[Property in keyof MutationObserverOptions<
TData,
TError,
TVariables,
TContext
>]: MaybeRefDeep<
MutationObserverOptions<TData, TError, TVariables, TContext>[Property]
>
}and then use it in https://github.com/TanStack/query/blob/main/packages/vue-query/src/useMutation.ts#L23 This will also require change in to use non reffed version of options which is currently at https://github.com/TanStack/query/blob/main/packages/vue-query/src/useMutation.ts#L23 |
|
@DamianOsipiuk thanks for the feedback gonna start on that now |
|
@DamianOsipiuk let me know what ya think! I'd like if functions could also be accepted as refs by tanstack query if possible but what do you think? (hence the change to the deep ref function) |
| test('should return error when request fails', async () => { | ||
| const mutation = useMutation(errorMutator) | ||
|
|
||
| mutation.mutate() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think changes in this file are relevant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok will take another look - for some reason or another passing no args was failing the tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually no idea.
Does it work on main branch?
What TS version do you have installed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that test is running on your cloud test suite - not my local so not sure if my ts version is relevant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export type MutateFunction<
TData = unknown,
TError = unknown,
TVariables = void,
TContext = unknown,
= (
variables: TVariables,
options?: MutateOptions<TData, TError, TVariables, TContext>,
) => Promise
it seems completely reasonable to get an error for not passing args - variables is not optional. Maybe I somehow removed a Partial somewhere... pretty strange
|
I have a separate concern with the current typing of the arguments - I see the most popular way to create reactive arguments to be to make a single options object, so const options = ref({ mutationKey: ..., mutationFn: ... }) currently, we do not allow for such an argument to be passed. I generally think that we should adjust the type signature to something like what I have just committed export type UseMutationOptions<TData, TError, TVariables, TContext> = The mutation options above are all non-reactive export type VueMutationObserverOptions<
} the Vue options use maybe deep ref on each key.... options: MaybeRef<VueMutationObserverOptions<TData, TError, TVariables, TContext>>, the object itself is allowed to be reactive |
|
Lastly I have tried all of the prettier formatting commands defined in package.json but still getting errors in the workflow tests somehow, any idea how to fix that? |
yeah, i think the Change |
|
worked like a charm thanks!!!!! |
Codecov ReportBase: 96.36% // Head: 92.28% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #4339 +/- ##
==========================================
- Coverage 96.36% 92.28% -4.08%
==========================================
Files 45 87 +42
Lines 2281 3563 +1282
Branches 640 904 +264
==========================================
+ Hits 2198 3288 +1090
- Misses 80 259 +179
- Partials 3 16 +13 Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
|
Woooo 🎉🎉🎉🎉🎉🎉🎉 test passed! lmk if you want to zoom or something and go over before we move forward. Thank you so much @DamianOsipiuk for the help it means so much to help with my first open source contribution :) |
|
Thanks for the contribution @matthewhausman 🚀 |
|
@allcontributors add @matthewhausman for code |
|
I've put up a pull request to add @matthewhausman! 🎉 |

Definitely need someone to help verify this implementation as I am not intimately familiar with how tanstack query is used professionally, only generally familiar.