Skip to content

Commit f4eb118

Browse files
author
Edward Upton
committed
fix(query): prioritize query over mutation for non-GET operations in generateQueryHook
1 parent 4a27aff commit f4eb118

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

packages/query/src/index.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,15 @@ const generateQueryHook = async (
11291129
isQuery = operationQueryOptions.useSuspenseQuery;
11301130
}
11311131

1132+
// For non-GET operations, only register query OR mutation hooks, not both
1133+
let isMutation =
1134+
operationQueryOptions.useMutation || override.query.useMutation;
1135+
1136+
// If both query and mutation are true for a non-GET operation, prioritize query
1137+
if (verb !== Verbs.GET && isQuery) {
1138+
isMutation = false;
1139+
}
1140+
11321141
if (isQuery) {
11331142
const queryKeyMutator = query.queryKey
11341143
? await generateMutator({
@@ -1286,11 +1295,6 @@ const generateQueryHook = async (
12861295
: undefined;
12871296
}
12881297

1289-
let isMutation = verb !== Verbs.GET && override.query.useMutation;
1290-
if (operationQueryOptions?.useMutation !== undefined) {
1291-
isMutation = operationQueryOptions.useMutation;
1292-
}
1293-
12941298
if (isMutation) {
12951299
const mutationOptionsMutator = query.mutationOptions
12961300
? await generateMutator({
@@ -1365,7 +1369,7 @@ const generateQueryHook = async (
13651369

13661370
const mutationOptionsFn = `export const ${mutationOptionsFnName} = <TError = ${errorType},
13671371
TContext = unknown>(${mutationArguments}): ${mutationOptionFnReturnType} => {
1368-
1372+
13691373
${hooksOptionImplementation}
13701374
13711375
${

0 commit comments

Comments
 (0)