@kubb/plugin-react-query 5.9.0-canary.20261029T142044 → 5.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -415,6 +415,11 @@ type Options = OutputOptions & {
415
415
  * A client plugin must be registered. The hooks always call its `<op>`.
416
416
  */
417
417
  client?: ClientSelector;
418
+ /**
419
+ * Shape of the value the hooks resolve to: `'data'` is the success body, `'full'` the client's whole `RequestResult` so a hook can read response headers. `'full'` needs a client plugin whose own `returnType` is `'full'` or `'plain'`.
420
+ * @default 'data'
421
+ */
422
+ returnType?: 'data' | 'full';
418
423
  /**
419
424
  * Skip operations matching at least one entry in the list.
420
425
  */
@@ -502,6 +507,7 @@ type ResolvedOptions = {
502
507
  * The resolved contract client the generators import and call.
503
508
  */
504
509
  client: ResolvedClient;
510
+ returnType?: 'data' | 'full';
505
511
  /**
506
512
  * Resolved infinite query configuration, or `false` when infinite queries are disabled.
507
513
  */
package/dist/index.d.ts CHANGED
@@ -415,6 +415,11 @@ type Options = OutputOptions & {
415
415
  * A client plugin must be registered. The hooks always call its `<op>`.
416
416
  */
417
417
  client?: ClientSelector;
418
+ /**
419
+ * Shape of the value the hooks resolve to: `'data'` is the success body, `'full'` the client's whole `RequestResult` so a hook can read response headers. `'full'` needs a client plugin whose own `returnType` is `'full'` or `'plain'`.
420
+ * @default 'data'
421
+ */
422
+ returnType?: 'data' | 'full';
418
423
  /**
419
424
  * Skip operations matching at least one entry in the list.
420
425
  */
@@ -502,6 +507,7 @@ type ResolvedOptions = {
502
507
  * The resolved contract client the generators import and call.
503
508
  */
504
509
  client: ResolvedClient;
510
+ returnType?: 'data' | 'full';
505
511
  /**
506
512
  * Resolved infinite query configuration, or `false` when infinite queries are disabled.
507
513
  */
package/dist/index.js CHANGED
@@ -26,19 +26,19 @@ function operationFileEntry(node, name, extname = ".ts") {
26
26
  };
27
27
  }
28
28
  /**
29
- * Resolves a dependency plugin's generated file for `node.operationId`, cached in `cache` (the
30
- * current node's `ctx.cache`) under the resolver's own plugin name. Several dependents reading the
29
+ * Resolves a dependency plugin's generated file for `node.operationId`, cached in `memo` (the
30
+ * build's `ctx.memo`) under the resolver's own plugin name and the operation. Several dependents reading the
31
31
  * same dependency for the same operation in one pass (a query plugin's several hook generators, the
32
32
  * MCP handler, ...) share one computed name and path instead of each calling `resolver.file` again.
33
33
  *
34
34
  * @example Cache `plugin-ts`'s file for the current operation
35
35
  * ```ts
36
- * const fileTs = resolveDependencyOperationFile({ cache: ctx.cache, node, resolver: tsResolver, root, output })
36
+ * const fileTs = resolveDependencyOperationFile({ memo: ctx.memo, node, resolver: tsResolver, root, output })
37
37
  * ```
38
38
  */
39
39
  function resolveDependencyOperationFile(options) {
40
- const { cache, node, resolver, root, output, group } = options;
41
- return cache.ensureItem(`${resolver.pluginName}:operationFile`, () => resolver.file({
40
+ const { memo, node, resolver, root, output, group } = options;
41
+ return memo(`${resolver.pluginName}:operationFile:${node.operationId}`, () => resolver.file({
42
42
  ...operationFileEntry(node, node.operationId),
43
43
  root,
44
44
  output,
@@ -483,7 +483,7 @@ var compatibility = {
483
483
  "node": ">=22.22"
484
484
  };
485
485
  // package.json
486
- var version = "5.9.0-canary.20261029T142044";
486
+ var version = "5.9.0";
487
487
  // ../../internals/client/src/resolveOperationTypes.ts
488
488
  /**
489
489
  * A `plugin-ts` shaped resolver whose operation type names point at the types `pluginZod({ inferred })`
@@ -680,7 +680,7 @@ function resolveImportPath(options) {
680
680
  * output root, the same path consumers read `RequestConfig` / `ResponseErrorConfig` from.
681
681
  * With plugin-client they come from the user's `importPath` module instead.
682
682
  *
683
- * The result is cached in the current node's `cache` (`ctx.cache`) under the client plugin's name,
683
+ * The result is cached in `memo` (the build's `ctx.memo`) under the client plugin's name and the operation,
684
684
  * so several dependents reading the same client plugin for one operation in a single pass
685
685
  * (react-query's query/mutation/infinite generators, vue-query, swr, the MCP handler, ...) share
686
686
  * one computed result instead of each re-deriving the name and path.
@@ -690,9 +690,9 @@ function resolveImportPath(options) {
690
690
  * and import path therefore match the `<op>` actually emitted, even when an `override` changes it.
691
691
  */
692
692
  function resolveClientOperation(options) {
693
- const { clientPlugin, driver, node, root, output, cache } = options;
693
+ const { clientPlugin, driver, node, root, output, memo } = options;
694
694
  if (!clientPlugin) return null;
695
- return cache.ensureItem(`${clientPlugin.pluginName}:clientOperation`, () => {
695
+ return memo(`${clientPlugin.pluginName}:clientOperation:${node.operationId}`, () => {
696
696
  const resolver = driver.getResolver(clientPlugin.pluginName);
697
697
  const pluginOptions = driver.getPlugin(clientPlugin.pluginName)?.options ?? {};
698
698
  const { exclude, include, override } = pluginOptions;
@@ -732,8 +732,16 @@ function resolveClientOperation(options) {
732
732
  * `pluginZod({ inferred: 'codec' })`), banner and footer.
733
733
  */
734
734
  function resolveHookFile(node, ctx, options) {
735
- const { name, output, group, contractOp, keyTypeName, extraTypeNames = [] } = options;
735
+ const { name, output, group, contractOp, keyTypeName, extraTypeNames = [], returnType = "data" } = options;
736
736
  const { config, root, resolver } = ctx;
737
+ if (returnType !== "data" && contractOp.returnType === "data") throw new Diagnostics.Error({
738
+ code: Diagnostics.code.invalidPluginOptions,
739
+ severity: "error",
740
+ message: `Option \`returnType\` is '${returnType}' for ${node.operationId}, but the client plugin has \`returnType: 'data'\` and only returns the response body.`,
741
+ help: "Set the client plugin's `returnType` to 'full', or set the hook plugin's `returnType` to 'data'.",
742
+ location: { kind: "config" },
743
+ plugin: resolver.pluginName
744
+ });
737
745
  const types = resolveOperationTypes(ctx.driver, resolver.pluginName);
738
746
  const tsResolver = types.resolver;
739
747
  const file = resolver.file({
@@ -743,7 +751,7 @@ function resolveHookFile(node, ctx, options) {
743
751
  group: group ?? void 0
744
752
  });
745
753
  const fileTs = resolveDependencyOperationFile({
746
- cache: ctx.cache,
754
+ memo: ctx.memo,
747
755
  node,
748
756
  resolver: tsResolver,
749
757
  root,
@@ -752,9 +760,10 @@ function resolveHookFile(node, ctx, options) {
752
760
  });
753
761
  const importedTypeNames = [
754
762
  tsResolver.response.options(node),
763
+ tsResolver.response.responses(node),
755
764
  ...extraTypeNames,
756
765
  ...resolveOperationTypeNames(node, tsResolver, {
757
- exclude: keyTypeName ? [keyTypeName] : void 0,
766
+ exclude: [keyTypeName, returnType !== "data" ? tsResolver.response.response(node) : null].filter((name) => Boolean(name)),
758
767
  order: "body-response-first",
759
768
  includeParams: false
760
769
  })
@@ -769,6 +778,7 @@ function resolveHookFile(node, ctx, options) {
769
778
  tsResolver,
770
779
  contractOp,
771
780
  importedTypeNames,
781
+ returnType,
772
782
  banner: resolver.default.banner(ctx.meta, {
773
783
  output,
774
784
  config,
@@ -799,7 +809,11 @@ function HookFile({ hook, imports, children }) {
799
809
  path: contractOp.path
800
810
  }),
801
811
  /* @__PURE__ */ jsx(File.Import, {
802
- name: ["RequestConfig", "ResponseErrorConfig"],
812
+ name: [
813
+ "RequestConfig",
814
+ "ResponseErrorConfig",
815
+ "RequestResult"
816
+ ],
803
817
  root: contractOp.clientPathIsFile ? file.path : void 0,
804
818
  path: contractOp.clientPath,
805
819
  isTypeOnly: true
@@ -929,11 +943,12 @@ function buildClientCall(node, options) {
929
943
  }
930
944
  /**
931
945
  * Builds the query/mutation body that resolves a `buildClientCall` expression down to the bare
932
- * success body. `returnType` mirrors the registered client plugin's own `returnType` option: with
946
+ * success body. `clientReturnType` mirrors the registered client plugin's own `returnType` option: with
933
947
  * `'data'` the call already resolves to the bare body, so it is returned directly; with `'full'`
934
948
  * (the default) the call carries `unwrap()`, so the body calls it instead of destructuring `data`
935
949
  * off the full result by hand. With `'plain'` (plugin-client) the call resolves to the user's
936
- * `RequestResult`, so the body awaits it and reads `data`.
950
+ * `RequestResult`, so the body awaits it and reads `data`. With `returnType` `'full'` the body
951
+ * resolves to the whole `RequestResult`; `resolveHookFile` rejects that for a client that already stripped it.
937
952
  *
938
953
  * @example
939
954
  * ```ts
@@ -942,22 +957,24 @@ function buildClientCall(node, options) {
942
957
  * ```
943
958
  */
944
959
  function buildCallResultBody(call, options = {}) {
945
- const { returnType = "full" } = options;
946
- if (returnType === "data") return `return await ${call}`;
947
- if (returnType === "plain") return `return (await ${call}).data`;
960
+ const { clientReturnType = "full", returnType = "data" } = options;
961
+ if (returnType !== "data" || clientReturnType === "data") return `return ${call}`;
962
+ if (clientReturnType === "plain") return `return (await ${call}).data`;
948
963
  return `return ${call}.unwrap()`;
949
964
  }
950
965
  /**
951
966
  * Builds the `TData` / `TError` type expressions shared by every generated hook, joining the resolved
952
967
  * success responses into `TData` and wrapping the error responses in `ResponseErrorConfig<...>`.
968
+ * With `returnType` `'full'`, `TData` is the client's `RequestResult` over the operation's responses record.
953
969
  */
954
- function buildResponseTypes(node, resolver) {
955
- return resolver.memo(`responseTypes:${node.method}\0${node.path}`, () => {
970
+ function buildResponseTypes(node, resolver, options = {}) {
971
+ const { returnType = "data" } = options;
972
+ return resolver.memo(`responseTypes:${returnType}:${node.method}\0${node.path}`, () => {
956
973
  const successNames = resolveSuccessNames(node, resolver);
957
974
  const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
958
975
  const errorNames = resolveErrorNames(node, resolver);
959
976
  return {
960
- TData: responseName,
977
+ TData: returnType !== "data" ? `RequestResult<${resolver.response.responses(node)}, true>` : responseName,
961
978
  TError: `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`
962
979
  };
963
980
  });
@@ -1186,8 +1203,9 @@ function buildResolvedRequestParams(node) {
1186
1203
  // ../../internals/tanstack-query/src/components/InfiniteQueryOptions.tsx
1187
1204
  const declarationPrinter$6 = functionPrinter({ mode: "declaration" });
1188
1205
  const callPrinter$3 = functionPrinter({ mode: "call" });
1189
- function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitInitialPageParam, cursorParam, nextParam, previousParam, getNextPageParam, getPreviousPageParam, node, tsResolver, queryParam, queryKeyName, queryKeyType = "typeof queryKey", memberTypeWrapper, unwrapName, returnType = "full" }) {
1190
- const { TData: queryFnDataType, TError: errorType } = buildResponseTypes(node, tsResolver);
1206
+ function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitInitialPageParam, cursorParam, nextParam, previousParam, getNextPageParam, getPreviousPageParam, node, tsResolver, queryParam, queryKeyName, queryKeyType = "typeof queryKey", memberTypeWrapper, unwrapName, clientReturnType, returnType }) {
1207
+ const { TData: queryFnDataType, TError: errorType } = buildResponseTypes(node, tsResolver, { returnType });
1208
+ const dataSuffix = returnType === "data" ? "" : ".data";
1191
1209
  const { queryParamsTypeName, pageParamType } = resolvePageParamType(node, {
1192
1210
  resolver: tsResolver,
1193
1211
  initialPageParam,
@@ -1209,21 +1227,24 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitI
1209
1227
  clientName,
1210
1228
  signal: true,
1211
1229
  unwrapName
1212
- }), { returnType });
1230
+ }), {
1231
+ clientReturnType,
1232
+ returnType
1233
+ });
1213
1234
  const initialPageParamLiteral = typeof initialPageParam === "string" || typeof initialPageParam === "object" && initialPageParam !== null ? JSON.stringify(initialPageParam) : String(initialPageParam === void 0 ? 0 : initialPageParam);
1214
1235
  const serializedGetNextPageParam = typeof getNextPageParam === "function" ? getNextPageParam.toString() : getNextPageParam;
1215
1236
  const getNextPageParamExpr = (() => {
1216
1237
  if (serializedGetNextPageParam) return `getNextPageParam: ${serializedGetNextPageParam}`;
1217
- if (nextParam) return `getNextPageParam: (lastPage) => ${getNestedAccessor(nextParam, "lastPage")}`;
1218
- if (cursorParam) return `getNextPageParam: (lastPage) => lastPage['${cursorParam}']`;
1219
- return "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1";
1238
+ if (nextParam) return `getNextPageParam: (lastPage) => ${getNestedAccessor(nextParam, `lastPage${dataSuffix}`)}`;
1239
+ if (cursorParam) return `getNextPageParam: (lastPage) => lastPage${dataSuffix}['${cursorParam}']`;
1240
+ return `getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage${dataSuffix}) && lastPage${dataSuffix}.length === 0 ? undefined : lastPageParam + 1`;
1220
1241
  })();
1221
1242
  const serializedGetPreviousPageParam = typeof getPreviousPageParam === "function" ? getPreviousPageParam.toString() : getPreviousPageParam;
1222
1243
  const defaultPreviousThreshold = hasExplicitInitialPageParam ? initialPageParamLiteral : "1";
1223
1244
  const getPreviousPageParamExpr = (() => {
1224
1245
  if (serializedGetPreviousPageParam) return `getPreviousPageParam: ${serializedGetPreviousPageParam}`;
1225
- if (previousParam) return `getPreviousPageParam: (firstPage) => ${getNestedAccessor(previousParam, "firstPage")}`;
1226
- if (cursorParam) return `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`;
1246
+ if (previousParam) return `getPreviousPageParam: (firstPage) => ${getNestedAccessor(previousParam, `firstPage${dataSuffix}`)}`;
1247
+ if (cursorParam) return `getPreviousPageParam: (firstPage) => firstPage${dataSuffix}['${cursorParam}']`;
1227
1248
  if (serializedGetNextPageParam || nextParam) return null;
1228
1249
  return `getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= ${defaultPreviousThreshold} ? undefined : firstPageParam - 1`;
1229
1250
  })();
@@ -1663,7 +1684,7 @@ function buildHookTypes({ node, tsResolver, infinite, suspense, TData, TError, q
1663
1684
  `TPageParam = ${pageParamType}`
1664
1685
  ],
1665
1686
  observerOptionsType: `${observerOptionsName}<TQueryFnData, TError, TData, TQueryKey, TPageParam>`,
1666
- returnType: `${resultTypeName}<TData, TError> & { queryKey: TQueryKey }`
1687
+ resultType: `${resultTypeName}<TData, TError> & { queryKey: TQueryKey }`
1667
1688
  };
1668
1689
  }
1669
1690
  return {
@@ -1684,15 +1705,15 @@ function buildHookTypes({ node, tsResolver, infinite, suspense, TData, TError, q
1684
1705
  "TQueryData",
1685
1706
  "TQueryKey"
1686
1707
  ]).join(", ")}>`,
1687
- returnType: `${resultTypeName}<TData, ${TError}> & { queryKey: TQueryKey }`
1708
+ resultType: `${resultTypeName}<TData, ${TError}> & { queryKey: TQueryKey }`
1688
1709
  };
1689
1710
  }
1690
- function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, customOptions, suspense, infinite }) {
1691
- const { TData, TError } = buildResponseTypes(node, tsResolver);
1711
+ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, customOptions, suspense, infinite, returnType }) {
1712
+ const { TData, TError } = buildResponseTypes(node, tsResolver, { returnType });
1692
1713
  const prefix = suspense ? "UseSuspense" : "Use";
1693
1714
  const hookName = `${suspense ? "useSuspense" : "use"}${infinite ? "InfiniteQuery" : "Query"}`;
1694
1715
  const observerOptionsName = OBSERVER_OPTIONS_NAMES[infinite ? "infinite" : "plain"][suspense ? "suspense" : "standard"];
1695
- const { generics, observerOptionsType, returnType } = buildHookTypes({
1716
+ const { generics, observerOptionsType, resultType } = buildHookTypes({
1696
1717
  node,
1697
1718
  tsResolver,
1698
1719
  infinite,
@@ -1736,7 +1757,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
1736
1757
  ...${queryOptionsName}(${queryOptionsArgs}),${customOptions ? "\n ...customOptions," : ""}
1737
1758
  ...resolvedOptions,
1738
1759
  queryKey,
1739
- } as unknown as ${castType}, queryClient) as ${returnType}
1760
+ } as unknown as ${castType}, queryClient) as ${resultType}
1740
1761
 
1741
1762
  queryResult.queryKey = queryKey as TQueryKey
1742
1763
 
@@ -1748,8 +1769,8 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
1748
1769
  // src/components/QueryOptions.tsx
1749
1770
  const declarationPrinter$2 = functionPrinter({ mode: "declaration" });
1750
1771
  const callPrinter$2 = functionPrinter({ mode: "call" });
1751
- function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, returnType = "full" }) {
1752
- const { TData, TError } = buildResponseTypes(node, tsResolver);
1772
+ function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, clientReturnType, returnType }) {
1773
+ const { TData, TError } = buildResponseTypes(node, tsResolver, { returnType });
1753
1774
  const queryKeyParamsNode = buildQueryKeyParams(node, { resolver: tsResolver });
1754
1775
  const queryKeyParamsCall = callPrinter$2.print(queryKeyParamsNode) ?? "";
1755
1776
  const paramsNode = buildQueryOptionsParams(node, { resolver: tsResolver });
@@ -1757,7 +1778,10 @@ function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, return
1757
1778
  const queryFnBody = buildCallResultBody(buildClientCall(node, {
1758
1779
  clientName,
1759
1780
  signal: true
1760
- }), { returnType });
1781
+ }), {
1782
+ clientReturnType,
1783
+ returnType
1784
+ });
1761
1785
  return /* @__PURE__ */ jsx(File.Source, {
1762
1786
  name,
1763
1787
  isExportable: true,
@@ -1829,7 +1853,7 @@ function createQueryGenerator({ name, variant }) {
1829
1853
  node,
1830
1854
  root,
1831
1855
  output,
1832
- cache: ctx.cache
1856
+ memo: ctx.memo
1833
1857
  });
1834
1858
  if (!contractOp) return null;
1835
1859
  const importPath = query ? query.importPath : "@tanstack/react-query";
@@ -1844,6 +1868,7 @@ function createQueryGenerator({ name, variant }) {
1844
1868
  output,
1845
1869
  group,
1846
1870
  contractOp,
1871
+ returnType: ctx.options.returnType,
1847
1872
  keyTypeName: queryKeyTypeName,
1848
1873
  extraTypeNames: infiniteOptions ? [resolvePageParamType(node, {
1849
1874
  resolver: tsResolver,
@@ -1890,7 +1915,8 @@ function createQueryGenerator({ name, variant }) {
1890
1915
  initialPageParam: infiniteOptions.initialPageParam,
1891
1916
  hasExplicitInitialPageParam: infiniteOptions.hasExplicitInitialPageParam,
1892
1917
  queryParam: infiniteOptions.queryParam,
1893
- returnType: contractOp.returnType
1918
+ clientReturnType: contractOp.returnType,
1919
+ returnType: hook.returnType
1894
1920
  })
1895
1921
  ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Import, {
1896
1922
  name: ["queryOptions"],
@@ -1901,7 +1927,8 @@ function createQueryGenerator({ name, variant }) {
1901
1927
  queryKeyName,
1902
1928
  node,
1903
1929
  tsResolver: hook.tsResolver,
1904
- returnType: contractOp.returnType
1930
+ clientReturnType: contractOp.returnType,
1931
+ returnType: hook.returnType
1905
1932
  })] }),
1906
1933
  (variant !== "query" || query && hooks) && /* @__PURE__ */ jsxs(Fragment, { children: [
1907
1934
  /* @__PURE__ */ jsx(File.Import, {
@@ -1925,6 +1952,7 @@ function createQueryGenerator({ name, variant }) {
1925
1952
  node,
1926
1953
  tsResolver: hook.tsResolver,
1927
1954
  customOptions,
1955
+ returnType: hook.returnType,
1928
1956
  suspense,
1929
1957
  infinite: infiniteOptions ? {
1930
1958
  initialPageParam: infiniteOptions.initialPageParam,
@@ -1959,8 +1987,8 @@ function buildMutationConfigParamsNode(node) {
1959
1987
  default: "{}"
1960
1988
  })] });
1961
1989
  }
1962
- function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName, returnType = "full" }) {
1963
- const { TData, TError } = buildResponseTypes(node, tsResolver);
1990
+ function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName, clientReturnType, returnType }) {
1991
+ const { TData, TError } = buildResponseTypes(node, tsResolver, { returnType });
1964
1992
  const configParamsNode = buildMutationConfigParamsNode(node);
1965
1993
  const paramsSignature = declarationPrinter$1.print(configParamsNode) ?? "";
1966
1994
  const groupedParam = buildGroupedRequestParam(node, {
@@ -1975,8 +2003,11 @@ function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName,
1975
2003
  clientName,
1976
2004
  signal: false,
1977
2005
  withContentType: true,
2006
+ returnType: clientReturnType
2007
+ }), {
2008
+ clientReturnType,
1978
2009
  returnType
1979
- }), { returnType });
2010
+ });
1980
2011
  return /* @__PURE__ */ jsx(File.Source, {
1981
2012
  name,
1982
2013
  isExportable: true,
@@ -2002,8 +2033,8 @@ function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName,
2002
2033
  const declarationPrinter = functionPrinter({ mode: "declaration" });
2003
2034
  const callPrinter = functionPrinter({ mode: "call" });
2004
2035
  function buildMutationParamsNode(node, options) {
2005
- const { resolver } = options;
2006
- const { TData, TError } = buildResponseTypes(node, resolver);
2036
+ const { resolver, returnType } = options;
2037
+ const { TData, TError } = buildResponseTypes(node, resolver, { returnType });
2007
2038
  return buildHookParams(node, {
2008
2039
  resolver,
2009
2040
  withRequest: false,
@@ -2018,18 +2049,21 @@ function buildMutationParamsNode(node, options) {
2018
2049
  }`
2019
2050
  });
2020
2051
  }
2021
- function Mutation({ name, mutationOptionsName, node, tsResolver, mutationKeyName, customOptions }) {
2022
- const { TData, TError } = buildResponseTypes(node, tsResolver);
2052
+ function Mutation({ name, mutationOptionsName, node, tsResolver, mutationKeyName, customOptions, returnType }) {
2053
+ const { TData, TError } = buildResponseTypes(node, tsResolver, { returnType });
2023
2054
  const generics = [
2024
2055
  TData,
2025
2056
  TError,
2026
2057
  resolveMutationRequestType(node, tsResolver),
2027
2058
  "TContext"
2028
2059
  ].join(", ");
2029
- const returnType = `UseMutationResult<${generics}>`;
2060
+ const resultType = `UseMutationResult<${generics}>`;
2030
2061
  const mutationOptionsConfigNode = buildMutationConfigParamsNode(node);
2031
2062
  const mutationOptionsParamsCall = callPrinter.print(mutationOptionsConfigNode) ?? "";
2032
- const paramsNode = buildMutationParamsNode(node, { resolver: tsResolver });
2063
+ const paramsNode = buildMutationParamsNode(node, {
2064
+ resolver: tsResolver,
2065
+ returnType
2066
+ });
2033
2067
  const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
2034
2068
  return /* @__PURE__ */ jsx(File.Source, {
2035
2069
  name,
@@ -2052,7 +2086,7 @@ function Mutation({ name, mutationOptionsName, node, tsResolver, mutationKeyName
2052
2086
  ...baseOptions,${customOptions ? "\n ...customOptions," : ""}
2053
2087
  mutationKey,
2054
2088
  ...mutationOptions,
2055
- }, queryClient) as ${returnType}
2089
+ }, queryClient) as ${resultType}
2056
2090
  `
2057
2091
  })
2058
2092
  });
@@ -2086,7 +2120,7 @@ const mutationGenerator = defineGenerator({
2086
2120
  node,
2087
2121
  root,
2088
2122
  output,
2089
- cache: ctx.cache
2123
+ memo: ctx.memo
2090
2124
  });
2091
2125
  if (!contractOp) return null;
2092
2126
  const mutationHookName = resolver.mutation.name(node);
@@ -2096,7 +2130,8 @@ const mutationGenerator = defineGenerator({
2096
2130
  name: mutationHookName,
2097
2131
  output,
2098
2132
  group,
2099
- contractOp
2133
+ contractOp,
2134
+ returnType: ctx.options.returnType
2100
2135
  });
2101
2136
  const { tsResolver } = hook;
2102
2137
  return /* @__PURE__ */ jsxs(HookFile, {
@@ -2121,7 +2156,8 @@ const mutationGenerator = defineGenerator({
2121
2156
  mutationKeyName,
2122
2157
  node,
2123
2158
  tsResolver,
2124
- returnType: contractOp.returnType
2159
+ clientReturnType: contractOp.returnType,
2160
+ returnType: hook.returnType
2125
2161
  }),
2126
2162
  mutation && hooks && /* @__PURE__ */ jsxs(Fragment, { children: [
2127
2163
  /* @__PURE__ */ jsx(File.Import, {
@@ -2143,7 +2179,8 @@ const mutationGenerator = defineGenerator({
2143
2179
  mutationKeyName,
2144
2180
  node,
2145
2181
  tsResolver,
2146
- customOptions
2182
+ customOptions,
2183
+ returnType: hook.returnType
2147
2184
  })
2148
2185
  ] })
2149
2186
  ]
@@ -2278,7 +2315,7 @@ const pluginReactQuery = defineExtension({
2278
2315
  const { output = {
2279
2316
  path: "hooks",
2280
2317
  barrel: { type: "named" }
2281
- }, group, exclude = [], include, override = [], suspense = false, infinite = false, mutation = {}, query = {}, mutationKey = mutationKeyTransformer, queryKey = queryKeyTransformer, customOptions, hooks = false, client, resolver: userResolver, macros: userMacros } = options;
2318
+ }, group, exclude = [], include, override = [], suspense = false, infinite = false, mutation = {}, query = {}, mutationKey = mutationKeyTransformer, queryKey = queryKeyTransformer, customOptions, hooks = false, client, returnType = "data", resolver: userResolver, macros: userMacros } = options;
2282
2319
  const resolver = userResolver ? Resolver.merge(resolverReactQuery, userResolver) : resolverReactQuery;
2283
2320
  setResolver(resolver);
2284
2321
  if (userMacros?.length) setMacros(userMacros);
@@ -2290,6 +2327,7 @@ const pluginReactQuery = defineExtension({
2290
2327
  client,
2291
2328
  plugins: useConfig().plugins
2292
2329
  }),
2330
+ returnType,
2293
2331
  queryKey,
2294
2332
  query: resolveQueryConfig(query, { importPath: "@tanstack/react-query" }),
2295
2333
  mutationKey,