Skip to content

Commit b1338c1

Browse files
authored
fix(query): override operation mutation and query conflict (#2079)
1 parent c5d45fc commit b1338c1

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

packages/query/src/index.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,7 @@ const generateQueryHook = async (
11321132
override.query.useSuspenseQuery ||
11331133
override.query.useInfinite ||
11341134
override.query.useSuspenseInfiniteQuery);
1135+
11351136
if (operationQueryOptions?.useInfinite !== undefined) {
11361137
isQuery = operationQueryOptions.useInfinite;
11371138
}
@@ -1145,16 +1146,22 @@ const generateQueryHook = async (
11451146
isQuery = operationQueryOptions.useSuspenseQuery;
11461147
}
11471148

1148-
// For non-GET operations, only register query OR mutation hooks, not both
1149-
let isMutation =
1150-
verb !== Verbs.GET &&
1151-
(operationQueryOptions?.useMutation || override.query.useMutation);
1149+
let isMutation = override.query.useMutation && verb !== Verbs.GET;
1150+
1151+
if (operationQueryOptions?.useMutation !== undefined) {
1152+
isMutation = operationQueryOptions.useMutation;
1153+
}
11521154

11531155
// If both query and mutation are true for a non-GET operation, prioritize query
11541156
if (verb !== Verbs.GET && isQuery) {
11551157
isMutation = false;
11561158
}
11571159

1160+
// If both query and mutation are true for a GET operation, prioritize mutation
1161+
if (verb === Verbs.GET && isMutation) {
1162+
isQuery = false;
1163+
}
1164+
11581165
if (isQuery) {
11591166
const queryKeyMutator = query.queryKey
11601167
? await generateMutator({

0 commit comments

Comments
 (0)