Skip to content

Commit 2e7a08c

Browse files
committed
fix(query): honor per-operation useMutation override for GET operations
A per-operation `override.operations.<id>.query.useMutation: true` was silently discarded for GET operations: the operation stayed a Query hook instead of becoming a Mutation hook. This was the inverse asymmetry of the per-operation `useQuery: true` path, which already worked for non-GET verbs. `effectiveUseMutation` already encodes the per-verb default (`verb !== Verbs.GET`), so the extra `&& verb !== Verbs.GET` gate on `isMutation` only ever suppressed an explicit opt-in. Drop the gate so `isMutation` honors explicit intent for every verb, mirroring how `isQuery` honors `useQuery: true` for non-GET verbs. Closes #3358
1 parent e3b888e commit 2e7a08c

24 files changed

Lines changed: 1326 additions & 6 deletions

File tree

docs/content/docs/reference/configuration/output.mdx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -693,11 +693,20 @@ restriction for individual operations.
693693

694694
**Type:** `Boolean`
695695

696-
**Default:** `true` for non-`GET` operations.
697-
698-
Generate `useMutation` hooks for non-`GET` operations. Set to `false`
699-
to suppress Mutation hook generation; pair with `useQuery: true` if
700-
you want non-`GET` operations to be generated as Query hooks instead.
696+
**Default:** `true` for non-`GET` operations; `false` otherwise.
697+
698+
Generate `useMutation` hooks. When set explicitly, applies to **all
699+
operations regardless of HTTP verb** — setting `useMutation: true`
700+
(globally or via `override.operations.<id>.query.useMutation`) routes
701+
a `GET` operation to a `useMutation` hook as well. This is useful for
702+
`GET` endpoints that you want to trigger imperatively rather than on
703+
render.
704+
705+
Set to `false` to suppress Mutation hook generation; pair with
706+
`useQuery: true` if you want non-`GET` operations to be generated as
707+
Query hooks instead. When both `useQuery` and `useMutation` resolve to
708+
`true` for the same operation, the Mutation hook wins for `GET` and the
709+
Query hook wins for non-`GET`.
701710

702711
### useInfinite
703712

packages/query/src/query-generator.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,12 @@ export const generateQueryHook = async (
833833
effectiveUseInfinite ||
834834
effectiveUseSuspenseInfiniteQuery;
835835

836-
let isMutation = effectiveUseMutation && verb !== Verbs.GET;
836+
// No verb gate here: `effectiveUseMutation` already encodes the
837+
// per-verb default (`verb !== Verbs.GET`), so an explicit
838+
// `useMutation: true` — global or per-operation — must be honoured for
839+
// GET operations too, mirroring how `isQuery` honours `useQuery: true`
840+
// for non-GET verbs (#3358).
841+
let isMutation = effectiveUseMutation;
837842

838843
// If both query and mutation are true for a non-GET operation, prioritize query
839844
if (verb !== Verbs.GET && isQuery) {

0 commit comments

Comments
 (0)