Skip to content

fix(plugin-react-query): only pass a query key argument when the factory accepts one - #806

Merged
stijnvanhulle merged 2 commits into
kubb-labs:mainfrom
xeoneux:ak/fix-react-query
Aug 28, 2026
Merged

fix(plugin-react-query): only pass a query key argument when the factory accepts one#806
stijnvanhulle merged 2 commits into
kubb-labs:mainfrom
xeoneux:ak/fix-react-query

Conversation

@xeoneux

@xeoneux xeoneux commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

For operations that only take header parameters (e.g. auth or correlation headers like X-Request-Id), the generated query key factory takes 0 parameters since transport headers are excluded from cache keys. However, the generated hook passed resolvedParams to the factory, causing TS2554: Expected 0 arguments, but got 1.
The signature and the call site derived their parameter expectations from different sets of request groups:

Request Groups
buildQueryKeyParams (signature) path, query, body
buildResolvedRequestParams (call site) path, query, body, headers
To keep them in sync, queryKeyGroupOrder and hasQueryKeyParams are now centralized in @internals/tanstack-query and shared across plugin-react-query and plugin-vue-query:
export const queryKeyGroupOrder = ['path', 'query', 'body'] as const
export function hasQueryKeyParams(node: ast.OperationNode): boolean {
  const groups = getRequestGroups(node)
  return queryKeyGroupOrder.some((key) => groups[key])
}
In `plugin-react-query`, both `Query.tsx` (`useQuery` / `useSuspenseQuery`) and `InfiniteQuery.tsx` (`useInfiniteQuery` / `useSuspenseInfiniteQuery`) now check `hasQueryKeyParams(node)` before passing `resolvedParams`:

```diff
- const queryKeyArgs = resolvedParams ? 'resolvedParams' : ''
+ const queryKeyArgs = resolvedParams && hasQueryKeyParams(node) ? 'resolvedParams' : ''

queryOptions continues to receive resolvedParams so header parameters are still properly forwarded to the underlying client call.

Generated output for a header-only operation:

  const resolvedParams = { headers: typeof headers === 'function' ? headers() : headers }
- const queryKey = resolvedOptions?.queryKey ?? retrieveMyProfileQueryKey(resolvedParams)
+ const queryKey = resolvedOptions?.queryKey ?? retrieveMyProfileQueryKey()
  const queryResult = useQuery({
    ...retrieveMyProfileQueryOptions(resolvedParams, config),
    ...resolvedOptions,
    queryKey,
  } as unknown as QueryObserverOptions, queryClient)

@codesandbox

codesandbox Bot commented Aug 27, 2026

Copy link
Copy Markdown

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Aug 27, 2026
@changeset-bot

changeset-bot Bot commented Aug 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 01e08b5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@kubb/plugin-react-query Patch

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

@github-actions github-actions Bot added the bug Something isn't working label Aug 27, 2026
@xeoneux
xeoneux force-pushed the ak/fix-react-query branch from 6ba0e47 to 44a6956 Compare August 27, 2026 19:46
@xeoneux

xeoneux commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

Fixes #805

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Aug 28, 2026
@stijnvanhulle

Copy link
Copy Markdown
Contributor

@xeoneux thanks again for opening a github issue and already fixing it, enjoy your work. Going to merge this in and create a new release for react-query and vue-query plugins.

@stijnvanhulle
stijnvanhulle merged commit 8cabf87 into kubb-labs:main Aug 28, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants