Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions docs/content/docs/reference/configuration/output.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -693,11 +693,20 @@ restriction for individual operations.

**Type:** `Boolean`

**Default:** `true` for non-`GET` operations.

Generate `useMutation` hooks for non-`GET` operations. Set to `false`
to suppress Mutation hook generation; pair with `useQuery: true` if
you want non-`GET` operations to be generated as Query hooks instead.
**Default:** `true` for non-`GET` operations; `false` otherwise.

Generate `useMutation` hooks. When set explicitly, applies to **all
operations regardless of HTTP verb** — setting `useMutation: true`
(globally or via `override.operations.<id>.query.useMutation`) routes
a `GET` operation to a `useMutation` hook as well. This is useful for
`GET` endpoints that you want to trigger imperatively rather than on
render.

Set to `false` to suppress Mutation hook generation; pair with
`useQuery: true` if you want non-`GET` operations to be generated as
Query hooks instead. When both `useQuery` and `useMutation` resolve to
`true` for the same operation, the Mutation hook wins for `GET` and the
Query hook wins for non-`GET`.

### useInfinite

Expand Down
7 changes: 6 additions & 1 deletion packages/query/src/query-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,12 @@ export const generateQueryHook = async (
effectiveUseInfinite ||
effectiveUseSuspenseInfiniteQuery;

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

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