feat: generate useMutation hooks for TanStack React Query plugin#3432
feat: generate useMutation hooks for TanStack React Query plugin#3432mrlubos merged 8 commits intohey-api:mainfrom
Conversation
|
|
|
Leaping into action... |
🦋 Changeset detectedLatest commit: 304a86f The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@nmokkenstorm is attempting to deploy a commit to the Hey API Team on Vercel. A member of the Team first needs to authorize it. |
It probably should actually? It's a non-breaking feature addition, happy to take some pointers re: changesets setup. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #3432 +/- ##
==========================================
- Coverage 40.31% 40.25% -0.06%
==========================================
Files 483 484 +1
Lines 17560 17591 +31
Branches 5317 5329 +12
==========================================
+ Hits 7080 7082 +2
- Misses 8427 8451 +24
- Partials 2053 2058 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
mrlubos
left a comment
There was a problem hiding this comment.
Not much I can say, this pull request looks very clean!
packages/openapi-ts/src/plugins/@tanstack/react-query/config.ts
Outdated
Show resolved
Hide resolved
packages/openapi-ts/src/plugins/@tanstack/react-query/config.ts
Outdated
Show resolved
Hide resolved
Thank you 🫶🏻 it's a relatively simple change that composes well and saves my personally quite a bit of boilerplate in application code so I thought I'd share. I do need a bit of time to figure out the testing strategy/merge checks, lmk if you have any tips there? |
|
@nmokkenstorm It looks good to me. You can run tests locally if you'd like to confirm. That heavy typecheck step is flaky in CI, I'm meant to split those tests because it's gotten too large, but other things are more important |
|
I'll fix what we discussed, run some local tests, report what I did and then we can continue 👍 |
|
@mrlubos looks good on my end! |
@hey-api/codegen-core
@hey-api/json-schema-ref-parser
@hey-api/nuxt
@hey-api/openapi-ts
@hey-api/shared
@hey-api/types
@hey-api/vite-plugin
commit: |

I wanted to expose react/tanstack query mutations in the same way the useQuery works, so now you get
useFooMutation(), no need to wire that through together. It greatly simplifies the consumption of mutation related code in a (private/corporate) codebase that I contribute to. We've been running a local fork with this feature.The generated
useMutationhooks reduce boilerplate in application/consumer code and save lot on small files that do manual wiring:Before:
After:
Before:
After:
One choice/tradeoff I made was to put the mutation options as a first positional argument, as the resulting mutation function seemed the neater way to pass in actual function arguments:
Without this ordering, every consumer that wants to pass
onSuccesshas to write:which was the more naive implementation I had at first, but the undefined everywhere for the positional arguments was bothering me. Now you set up your request stuff in the hook call, and request data in the execution of the resulting function, which seemed the more ergonomic approach.
This PR is first of three, as mentioned I am running a fork with some additional things for my project. I want use this as a starting point to get some discussion going and figure out how to collaborate / if a PR like this is appreciated or not. The actual code diff isn't that big, it's mostly wiring through a parameter that works the same way for
useQueryand the snapshot tests.