···11+---
22+'@hey-api/openapi-ts': minor
33+---
44+55+feat(tanstack-query): add name and case options
66+77+### Updated TanStack Query options
88+99+The TanStack Query plugin options have been expanded to support more naming and casing patterns. As a result, the following options have been renamed.
1010+1111+- `queryOptionsNameBuilder` renamed to `queryOptions`
1212+- `infiniteQueryOptionsNameBuilder` renamed to `infiniteQueryOptions`
1313+- `mutationOptionsNameBuilder` renamed to `mutationOptions`
1414+- `queryKeyNameBuilder` renamed to `queryKeys`
1515+- `infiniteQueryKeyNameBuilder` renamed to `infiniteQueryKeys`
+10
docs/openapi-ts/migrating.md
···29293030## v0.75.0
31313232+### Updated TanStack Query options
3333+3434+The TanStack Query plugin options have been expanded to support more naming and casing patterns. As a result, the following options have been renamed.
3535+3636+- `queryOptionsNameBuilder` renamed to `queryOptions`
3737+- `infiniteQueryOptionsNameBuilder` renamed to `infiniteQueryOptions`
3838+- `mutationOptionsNameBuilder` renamed to `mutationOptions`
3939+- `queryKeyNameBuilder` renamed to `queryKeys`
4040+- `infiniteQueryKeyNameBuilder` renamed to `infiniteQueryKeys`
4141+3242### Added `plugin.forEach()` method
33433444This method replaces the `.subscribe()` method. Additionally, `.forEach()` is executed immediately, which means we don't need the `before` and `after` events – simply move your code before and after the `.forEach()` block.
+54-40
docs/openapi-ts/plugins/tanstack-query.md
···3737::: code-group
38383939```js [react]
4040-import { defaultPlugins } from '@hey-api/openapi-ts';
4141-4240export default {
4341 input: 'https://get.heyapi.dev/hey-api/backend',
4442 output: 'src/client',
4543 plugins: [
4646- ...defaultPlugins,
4444+ // ...other plugins
4745 '@tanstack/react-query', // [!code ++]
4846 ],
4947};
5048```
51495250```js [vue]
5353-import { defaultPlugins } from '@hey-api/openapi-ts';
5454-5551export default {
5652 input: 'https://get.heyapi.dev/hey-api/backend',
5753 output: 'src/client',
5854 plugins: [
5959- ...defaultPlugins,
5555+ // ...other plugins
6056 '@tanstack/vue-query', // [!code ++]
6157 ],
6258};
6359```
64606561```js [angular]
6666-import { defaultPlugins } from '@hey-api/openapi-ts';
6767-6862export default {
6963 input: 'https://get.heyapi.dev/hey-api/backend',
7064 output: 'src/client',
7165 plugins: [
7272- ...defaultPlugins,
6666+ // ...other plugins
7367 '@tanstack/angular-query-experimental', // [!code ++]
7468 ],
7569};
7670```
77717872```js [svelte]
7979-import { defaultPlugins } from '@hey-api/openapi-ts';
8080-8173export default {
8274 input: 'https://get.heyapi.dev/hey-api/backend',
8375 output: 'src/client',
8476 plugins: [
8585- ...defaultPlugins,
7777+ // ...other plugins
8678 '@tanstack/svelte-query', // [!code ++]
8779 ],
8880};
8981```
90829183```js [solid]
9292-import { defaultPlugins } from '@hey-api/openapi-ts';
9393-9484export default {
9585 input: 'https://get.heyapi.dev/hey-api/backend',
9686 output: 'src/client',
9787 plugins: [
9898- ...defaultPlugins,
8888+ // ...other plugins
9989 '@tanstack/solid-query', // [!code ++]
10090 ],
10191};
···121111});
122112```
123113124124-You can customize query function names using `queryOptionsNameBuilder`.
114114+You can customize the naming and casing pattern for query options functions using the `queryOptions.name` and `queryOptions.case` options.
115115+116116+## Query Keys
117117+118118+If you have access to the result of query options function, you can get the query key from the `queryKey` field.
119119+120120+```ts
121121+const { queryKey } = getPetByIdOptions({
122122+ path: {
123123+ petId: 1,
124124+ },
125125+});
126126+```
127127+128128+Alternatively, you can access the same query key by calling query key functions. The generated query key functions follow the naming convention of SDK functions and by default append `QueryKey`, e.g. `getPetByIdQueryKey()`.
129129+130130+```ts
131131+const queryKey = getPetByIdQueryKey({
132132+ path: {
133133+ petId: 1,
134134+ },
135135+});
136136+```
137137+138138+You can customize the naming and casing pattern for query key functions using the `queryKeys.name` and `queryKeys.case` options.
125139126140## Infinite Queries
127141···139153});
140154```
141155142142-You can customize infinite query function names using `infiniteQueryOptionsNameBuilder`.
156156+You can customize the naming and casing pattern for infinite query options functions using the `infiniteQueryOptions.name` and `infiniteQueryOptions.case` options.
143157144144-## Mutations
158158+## Infinite Query Keys
145159146146-Mutations are generated from DELETE, PATCH, POST, and PUT endpoints. The generated mutation functions follow the naming convention of SDK functions and by default append `Mutation`, e.g. `addPetMutation()`.
160160+If you have access to the result of infinite query options function, you can get the query key from the `queryKey` field.
147161148162```ts
149149-const addPet = useMutation({
150150- ...addPetMutation(),
151151- onError: (error) => {
152152- console.log(error);
163163+const { queryKey } = getPetByIdInfiniteOptions({
164164+ path: {
165165+ petId: 1,
153166 },
154167});
168168+```
155169156156-addPet.mutate({
157157- body: {
158158- name: 'Kitty',
170170+Alternatively, you can access the same query key by calling query key functions. The generated query key functions follow the naming convention of SDK functions and by default append `InfiniteQueryKey`, e.g. `getPetByIdInfiniteQueryKey()`.
171171+172172+```ts
173173+const queryKey = getPetByIdInfiniteQueryKey({
174174+ path: {
175175+ petId: 1,
159176 },
160177});
161178```
162179163163-You can customize mutation function names using `mutationOptionsNameBuilder`.
180180+You can customize the naming and casing pattern for infinite query key functions using the `infiniteQueryKeys.name` and `infiniteQueryKeys.case` options.
164181165165-## Query Keys
182182+## Mutations
166183167167-Query keys are generated for both queries and infinite queries. If you have access to the result of query or infinite query options function, you can get the query key from the `queryKey` field.
184184+Mutations are generated from DELETE, PATCH, POST, and PUT endpoints. The generated mutation functions follow the naming convention of SDK functions and by default append `Mutation`, e.g. `addPetMutation()`.
168185169186```ts
170170-const { queryKey } = getPetByIdOptions({
171171- path: {
172172- petId: 1,
187187+const addPet = useMutation({
188188+ ...addPetMutation(),
189189+ onError: (error) => {
190190+ console.log(error);
173191 },
174192});
175175-```
176193177177-Alternatively, you can access the same query key by calling query key functions. The generated query key functions follow the naming convention of SDK functions and by default append `QueryKey` or `InfiniteQueryKey`, e.g. `getPetByIdQueryKey()` or `getPetByIdInfiniteQueryKey()`.
178178-179179-```ts
180180-const queryKey = getPetByIdQueryKey({
181181- path: {
182182- petId: 1,
194194+addPet.mutate({
195195+ body: {
196196+ name: 'Kitty',
183197 },
184198});
185199```
186200187187-You can customize query key function names using `queryKeyNameBuilder` and `infiniteQueryKeyNameBuilder`.
201201+You can customize the naming and casing pattern for mutation options functions using the `mutationOptions.name` and `mutationOptions.case` options.
188202189203<!--@include: ../../examples.md-->
190204<!--@include: ../../sponsors.md-->
···11import type { ImportExportItem } from '../../../compiler/module';
22import type { Plugin } from '../../types';
33-import type { Config as AngularQueryConfig } from '../angular-query-experimental';
44-import type { Config as ReactQueryConfig } from '../react-query';
55-import type { Config as SolidQueryConfig } from '../solid-query';
66-import type { Config as SvelteQueryConfig } from '../svelte-query';
77-import type { Config as VueQueryConfig } from '../vue-query';
33+import type { ResolvedConfig as AngularQueryResolvedConfig } from '../angular-query-experimental/types';
44+import type { ResolvedConfig as ReactQueryResolvedConfig } from '../react-query/types';
55+import type { ResolvedConfig as SolidQueryResolvedConfig } from '../solid-query/types';
66+import type { ResolvedConfig as SvelteQueryResolvedConfig } from '../svelte-query/types';
77+import type { ResolvedConfig as VueQueryResolvedConfig } from '../vue-query/types';
8899export type PluginHandler = Plugin.Handler<
1010- | AngularQueryConfig
1111- | ReactQueryConfig
1212- | SolidQueryConfig
1313- | SvelteQueryConfig
1414- | VueQueryConfig
1010+ | AngularQueryResolvedConfig
1111+ | ReactQueryResolvedConfig
1212+ | SolidQueryResolvedConfig
1313+ | SvelteQueryResolvedConfig
1414+ | VueQueryResolvedConfig
1515>;
16161717export type PluginInstance = Plugin.Instance<
1818- | AngularQueryConfig
1919- | ReactQueryConfig
2020- | SolidQueryConfig
2121- | SvelteQueryConfig
2222- | VueQueryConfig
1818+ | AngularQueryResolvedConfig
1919+ | ReactQueryResolvedConfig
2020+ | SolidQueryResolvedConfig
2121+ | SvelteQueryResolvedConfig
2222+ | VueQueryResolvedConfig
2323>;
24242525export interface PluginState {
···3131 hasUsedQueryFn: boolean;
3232 typeInfiniteData: ImportExportItem;
3333}
3434-3535-/**
3636- * Public TanStack Query API.
3737- */
3838-export namespace TanStackQuery {
3939- export type Config = {
4040- /**
4141- * Add comments from SDK functions to the generated TanStack Query code?
4242- * Duplicating comments this way is useful so you don't need to drill into
4343- * the underlying SDK function to learn what it does or whether it's
4444- * deprecated. You can set this option to `false` if you prefer less
4545- * comment duplication.
4646- *
4747- * @default true
4848- */
4949- comments?: boolean;
5050- /**
5151- * Should the exports from the generated files be re-exported in the index
5252- * barrel file?
5353- *
5454- * @default false
5555- */
5656- exportFromIndex?: boolean;
5757- /**
5858- * Customize the generated infinite query key names. The name variable is
5959- * obtained from the SDK function name.
6060- *
6161- * @default '{{name}}InfiniteQueryKey'
6262- */
6363- infiniteQueryKeyNameBuilder?: string | ((name: string) => string);
6464- /**
6565- * Customize the generated infinite query options names. The name variable
6666- * is obtained from the SDK function name.
6767- *
6868- * @default '{{name}}InfiniteOptions'
6969- */
7070- infiniteQueryOptionsNameBuilder?: string | ((name: string) => string);
7171- /**
7272- * Customize the generated mutation options names. The name variable is
7373- * obtained from the SDK function name.
7474- *
7575- * @default '{{name}}Mutation'
7676- */
7777- mutationOptionsNameBuilder?: string | ((name: string) => string);
7878- /**
7979- * Customize the generated query key names. The name variable is obtained
8080- * from the SDK function name.
8181- *
8282- * @default '{{name}}QueryKey'
8383- */
8484- queryKeyNameBuilder?: string | ((name: string) => string);
8585- /**
8686- * Customize the generated query options names. The name variable is
8787- * obtained from the SDK function name.
8888- *
8989- * @default '{{name}}Options'
9090- */
9191- queryOptionsNameBuilder?: string | ((name: string) => string);
9292- };
9393-}