feat: make TanStack Query plugin respect responseStyle: 'fields'#3662
feat: make TanStack Query plugin respect responseStyle: 'fields'#3662JorrinKievit wants to merge 6 commits intohey-api:mainfrom
Conversation
|
|
|
Someone is attempting to deploy a commit to the Hey API Team on Vercel. A member of the Team first needs to authorize it. |
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #3662 +/- ##
==========================================
- Coverage 38.98% 38.82% -0.17%
==========================================
Files 518 518
Lines 18968 19072 +104
Branches 5606 5620 +14
==========================================
+ Hits 7395 7405 +10
- Misses 9367 9451 +84
- Partials 2206 2216 +10
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:
|
@hey-api/codegen-core
@hey-api/json-schema-ref-parser
@hey-api/nuxt
@hey-api/openapi-ts
@hey-api/shared
@hey-api/spec-types
@hey-api/types
@hey-api/vite-plugin
commit: |
|
Reviewed PR #3662. Found a critical runtime/type mismatch bug where the default Task list (5/5 completed)
![]() |
There was a problem hiding this comment.
Thanks for working on this — the feature is genuinely useful and the overall design (plugin-level config + per-query TStyle override) is solid. There is one critical runtime bug and a few other issues that need addressing before this can merge.
Critical: The runtime conditional options?.responseStyle === 'fields' does not match when responseStyle is undefined (the common case when the user omits it), yet the type-level default for TStyle is 'fields'. This causes a type-safety violation where TypeScript thinks the return is { data, request, response } but the actual runtime value is just the unwrapped data.
Other issues: a regression where .export(plugin.config.mutationOptions.exported) was changed to .export(), duplicate imports, and heavy code duplication across three files that could be reduced significantly.
packages/openapi-ts/src/plugins/@tanstack/query-core/v5/mutationOptions.ts
Outdated
Show resolved
Hide resolved
packages/openapi-ts/src/plugins/@tanstack/query-core/v5/plugin.ts
Outdated
Show resolved
Hide resolved
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
8889ad1 to
9086190
Compare

Problem
When using the TanStack Query plugin, there's no way to access the HTTP
Responseobject — status codes, headers, or request metadata. The plugin always destructures{ data }from the SDK response and discards everything else, even whenresponseStyle: 'fields'is configured.This makes it impossible to:
X-Total-Count, rate-limit headers)QueryCache.onErrorRelated issues: #3628, #3632, #2070, #1762
Solution
This PR makes the TanStack Query plugin actually respect
responseStyle. A newresponseStyleconfig option is added to the plugin. I decided to have "data" as the default, since that kinda is happening right now for the plugin.Plugin-level config
Per-query override
Each generated function accepts a generic
TStyleparameter, so you can override per-query without changing the global default:Also works the other way — if the plugin default is
'fields', you can override specific queries back to'data'.Discussion point
For me the primary reason is being able to access the response type on Errors so I can handle them globally. But also included it for succesfull responses because I saw other issues.
What I don't like is that I kinda want to enable it globally, but only for Errors and not for the data itself. Because that would mean I am gonna have nested data objects everywhere 🤔