@kubb/plugin-vue-query 5.10.3 → 5.10.4

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.cjs CHANGED
@@ -31,11 +31,11 @@ let _kubb_renderer_jsx = require("@kubb/renderer-jsx");
31
31
  let _kubb_renderer_jsx_jsx_runtime = require("@kubb/renderer-jsx/jsx-runtime");
32
32
  // kubb-extension.json
33
33
  var compatibility = {
34
- "kubb": ">=5.18.4",
34
+ "kubb": ">=5.19.0",
35
35
  "node": ">=22.22"
36
36
  };
37
37
  // package.json
38
- var version = "5.10.3";
38
+ var version = "5.10.4";
39
39
  // ../../internals/client/src/resolveClient.ts
40
40
  /**
41
41
  * Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
package/dist/index.js CHANGED
@@ -5,11 +5,11 @@ import { File, Function, Type, jsxRenderer } from "@kubb/renderer-jsx";
5
5
  import { Fragment, jsx, jsxs } from "@kubb/renderer-jsx/jsx-runtime";
6
6
  // kubb-extension.json
7
7
  var compatibility = {
8
- "kubb": ">=5.18.4",
8
+ "kubb": ">=5.19.0",
9
9
  "node": ">=22.22"
10
10
  };
11
11
  // package.json
12
- var version = "5.10.3";
12
+ var version = "5.10.4";
13
13
  // ../../internals/client/src/resolveClient.ts
14
14
  /**
15
15
  * Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
@@ -1,64 +1,48 @@
1
1
  # Call operations
2
2
 
3
- `@kubb/plugin-vue-query` can generate a typed TanStack Query composable for each operation. `GET` operations get query composables such as `useGetPetById`, and `POST`, `PUT`, `PATCH`, and `DELETE` operations get mutation composables such as `useUpdatePetWithForm`. Each composable calls the client function from `@kubb/plugin-fetch`, `@kubb/plugin-axios`, or `@kubb/plugin-client`.
3
+ Use the generated TanStack Query composables and factories in Vue: queries, mutations, and infinite lists with reactive parameters.
4
4
 
5
- > [!IMPORTANT]
6
- > By default the plugin emits only the factory helpers (`queryOptions`, `queryKey`, `mutationKey`). Set [`hooks: true`](https://kubb.dev/extensions/kubb-labs/plugin-vue-query/options#hooks) in the plugin options to also generate the `use*` composables shown below.
5
+ ## What each plugin generates
7
6
 
8
- ## Queries
7
+ Each composable and its helpers live in a file named after the composable, such as `src/gen/hooks/useGetPetById.ts`.
9
8
 
10
- A query composable takes grouped request parameters as its first argument. Parameters accept a value, ref, or getter. See [reactive parameters](#refetch-when-parameters-change).
9
+ | Operation | Exports |
10
+ | ------------------------------------------- | --------------------------------------------------------------------------------------------------- |
11
+ | Query (`GET`, `QUERY`) | `getPetByIdQueryKey`, `getPetByIdQueryOptions`, plus `useGetPetById` with `hooks` |
12
+ | Mutation (`POST`, `PUT`, `PATCH`, `DELETE`) | `updatePetMutationKey`, plus `useUpdatePet` with `hooks` |
13
+ | Infinite, with `infinite` and `hooks` | `findPetsByTagsInfiniteQueryKey`, `findPetsByTagsInfiniteQueryOptions`, `useFindPetsByTagsInfinite` |
14
+ | Server-Sent Events or JSON Lines | Nothing. Call the client function directly. |
11
15
 
12
- ```typescript [usage.ts]
13
- import { useGetPetById } from './gen/hooks/useGetPetById'
16
+ ## Call a composable
14
17
 
15
- const { data, error, isLoading } = useGetPetById({ path: { petId: 1 } })
16
- ```
18
+ The examples set `hooks: true`, and [`integerType: 'number'`](https://kubb.dev/extensions/kubb-labs/adapter-oas/options#integertype) on the adapter so `petId` is a `number`. Path keys keep their spec names unless you set [`pathParamsCasing`](https://kubb.dev/extensions/kubb-labs/adapter-oas/options#pathparamscasing).
17
19
 
18
- The examples set [`integerType: 'number'`](https://kubb.dev/extensions/kubb-labs/adapter-oas/options#integertype) on the adapter, so an `int64` id such as `petId` is a `number`. With the default it is a `bigint` and the call takes `1n`.
20
+ ::tabs
19
21
 
20
- Path keys keep the names from the spec, so a `{pet-id}` placeholder is passed as `path: { 'pet-id': 1 }`. Set [`pathParamsCasing: 'camelcase'`](https://kubb.dev/extensions/kubb-labs/adapter-oas/options#pathparamscasing) on the adapter (`@kubb/adapter-oas` 5.20.0 or later) to pass `path: { petId: 1 }` instead, the name MSW handlers and query keys already use. The HTTP request stays the same.
22
+ :::tabs-item{label="Query"}
21
23
 
22
- The second argument has two optional groups. `query` takes any TanStack Query option, and `query.client` sets the `QueryClient` to use. The top-level `client` takes request config for this call, such as `baseURL`:
24
+ The first argument takes the request groups (`path`, `query`, `headers`), each as a value, a ref, or a getter. The second takes TanStack Query options in `query`, with `query.client` for the `QueryClient`, and request config such as `baseURL` in `client`.
23
25
 
24
26
  ```typescript
25
27
  import { useFindPetsByTags } from './gen/hooks/useFindPetsByTags'
26
28
 
27
- useFindPetsByTags(
29
+ const { data, error, isLoading } = useFindPetsByTags(
28
30
  { query: { tags: ['dog'] } },
29
- {
30
- query: { staleTime: 60_000 },
31
- client: { baseURL: 'https://api.example.com/v1' },
32
- },
31
+ { query: { staleTime: 60_000 }, client: { baseURL: 'https://api.example.com/v1' } },
33
32
  )
34
33
  ```
35
34
 
36
- ## Factories
37
-
38
- Every query operation also exports a `queryOptions` factory and a `queryKey` helper for prefetching and invalidation. The key is `[{ url }, query]`, built from the operation path and its query params:
39
-
40
- ```typescript
41
- import { useQueryClient } from '@tanstack/vue-query'
42
- import { findPetsByTagsQueryKey, findPetsByTagsQueryOptions } from './gen/hooks/useFindPetsByTags'
43
-
44
- const queryClient = useQueryClient()
45
-
46
- await queryClient.prefetchQuery(findPetsByTagsQueryOptions({ query: { tags: ['dog'] } }))
47
- queryClient.invalidateQueries({ queryKey: findPetsByTagsQueryKey({ query: { tags: ['dog'] } }) })
48
- ```
49
-
50
- Mutations export a `mutationKey` helper next to the composable.
35
+ :::
51
36
 
52
- ## Mutations
37
+ :::tabs-item{label="Mutation"}
53
38
 
54
- A mutation composable takes only an options object. The grouped request config is the mutation variable, so you pass it to `mutate` or `mutateAsync`:
39
+ A mutation composable takes only the options object, with `mutation` and `client`. Pass the request groups to `mutate` or `mutateAsync`.
55
40
 
56
41
  ```typescript
57
42
  import { useQueryClient } from '@tanstack/vue-query'
58
43
  import { useUpdatePetWithForm } from './gen/hooks/useUpdatePetWithForm'
59
44
 
60
45
  const queryClient = useQueryClient()
61
-
62
46
  const { mutate } = useUpdatePetWithForm({
63
47
  mutation: { onSuccess: () => queryClient.invalidateQueries() },
64
48
  })
@@ -66,70 +50,59 @@ const { mutate } = useUpdatePetWithForm({
66
50
  mutate({ path: { petId: 1 }, query: { name: 'Fluffy' } })
67
51
  ```
68
52
 
69
- ## Errors and transport
70
-
71
- Each generated composable calls the client function with `throwOnError: true`. A failed request sets TanStack Query's `error`, typed from the error responses in the spec. Set the base URL, authentication, interceptors, serialization, and validation on the client plugin. See the [plugin-fetch](https://kubb.dev/extensions/kubb-labs/plugin-fetch) or [plugin-axios](https://kubb.dev/extensions/kubb-labs/plugin-axios) guide. With [plugin-client](https://kubb.dev/extensions/kubb-labs/plugin-client), set these in your own client module.
72
-
73
- ## Customize cache keys
74
-
75
- Set `queryKey` on the plugin to change generated keys. String entries are emitted as source code, so use `JSON.stringify` for a string literal.
76
-
77
- ```typescript [kubb.config.ts]
78
- import { pluginVueQuery } from '@kubb/plugin-vue-query'
79
-
80
- pluginVueQuery({
81
- queryKey: ({ node }) => [JSON.stringify(node.operationId)],
82
- })
83
- ```
84
-
85
- > [!WARNING]
86
- > This `queryKey` gives every call the same key, such as `['getUserByName']`. If path or query values select different data, add them to the key.
87
-
88
- ## Load more pages
53
+ :::
89
54
 
90
- Configure `infinite` with a query parameter declared by the operation, its initial value, and the response path for the next cursor. Infinite output needs `hooks: true`, and only operations that declare the `queryParam` receive it.
55
+ :::tabs-item{label="Infinite"}
91
56
 
92
- ::code-group
57
+ Only operations that declare `infinite.queryParam` get an infinite composable. Point `nextParam` at the cursor in the response, and give `initialPageParam` the type of the query parameter. See [Infinite queries](https://kubb.dev/extensions/kubb-labs/plugin-vue-query/guides/infinite-queries).
93
58
 
94
59
  ```typescript [kubb.config.ts]
95
- import { pluginVueQuery } from '@kubb/plugin-vue-query'
96
-
97
60
  pluginVueQuery({
98
61
  hooks: true,
99
- infinite: {
100
- queryParam: 'page',
101
- initialPageParam: 0,
102
- nextParam: 'pagination.next.cursor',
103
- },
62
+ infinite: { queryParam: 'page', initialPageParam: 0, nextParam: 'pagination.next.cursor' },
104
63
  })
105
64
  ```
106
65
 
107
- ```typescript [usage.ts]
66
+ ```typescript
108
67
  import { useFindPetsByTagsInfinite } from './gen/hooks/useFindPetsByTagsInfinite'
109
68
 
110
- const { data, fetchNextPage, hasNextPage } = useFindPetsByTagsInfinite({
111
- query: () => ({ tags: ['dog'] }),
112
- })
69
+ const { data, fetchNextPage, hasNextPage } = useFindPetsByTagsInfinite({ query: () => ({ tags: ['dog'] }) })
113
70
  ```
114
71
 
115
- ::
72
+ :::
116
73
 
117
- `nextParam` takes dot notation or an array of keys. Change it to match your API's response, and give `initialPageParam` the same type as the query parameter. Without `getNextPageParam`, `nextParam` or `cursorParam`, the generated options increment the page number until a page returns an empty array.
74
+ ::
118
75
 
119
76
  ## Refetch when parameters change
120
77
 
121
- Enable `hooks: true`, then pass a ref or getter to a generated composable. Parameters accept `MaybeRefOrGetter`. A getter tracks its reactive dependencies.
78
+ Pass a ref or a getter instead of a value. A change updates the query key and fetches again:
122
79
 
123
- ```typescript [usage.ts]
80
+ ```typescript
124
81
  import { ref } from 'vue'
125
82
  import { useFindPetsByTags } from './gen/hooks/useFindPetsByTags'
126
83
 
127
84
  const tags = ref(['dog'])
128
- const { data, error, isLoading } = useFindPetsByTags({
129
- query: () => ({ tags: tags.value }),
130
- })
85
+ const { data } = useFindPetsByTags({ query: () => ({ tags: tags.value }) })
86
+
87
+ tags.value = ['cat'] // fetches the cat list
88
+ ```
89
+
90
+ ## Prefetch and invalidate
91
+
92
+ The factories work without `hooks`, so you can prefetch or invalidate outside a component:
93
+
94
+ ```typescript
95
+ import { findPetsByTagsQueryKey, findPetsByTagsQueryOptions } from './gen/hooks/useFindPetsByTags'
96
+ import { queryClient } from './queryClient' // the QueryClient you pass to VueQueryPlugin
131
97
 
132
- tags.value = ['cat']
98
+ await queryClient.prefetchQuery(findPetsByTagsQueryOptions({ query: { tags: ['dog'] } }))
99
+ queryClient.invalidateQueries({ queryKey: findPetsByTagsQueryKey({ query: { tags: ['dog'] } }) })
133
100
  ```
134
101
 
135
- Changing `tags.value` updates the query key and fetches the corresponding resource.
102
+ [TanStack Query keys](https://kubb.dev/extensions/kubb-labs/plugin-vue-query/guides/query-keys) shows the default keys. To change them, set [`queryKey`](https://kubb.dev/extensions/kubb-labs/plugin-vue-query/options#querykey) and [`mutationKey`](https://kubb.dev/extensions/kubb-labs/plugin-vue-query/options#mutationkey).
103
+
104
+ ## Handle errors
105
+
106
+ Each composable calls the client with `throwOnError: true`, so a failed request sets TanStack Query's `error`, typed from the spec's error responses.
107
+
108
+ Next, set the base URL, auth, and interceptors on your client plugin: [plugin-fetch](https://kubb.dev/extensions/kubb-labs/plugin-fetch), [plugin-axios](https://kubb.dev/extensions/kubb-labs/plugin-axios), or your own module with [plugin-client](https://kubb.dev/extensions/kubb-labs/plugin-client/guides/write-your-client).
@@ -0,0 +1,88 @@
1
+ # Infinite queries with useInfiniteQuery
2
+
3
+ Generate `useInfiniteQuery` composables for paginated endpoints, read the next cursor from the response, and stop once the last page arrives.
4
+
5
+ ## Generate infinite composables
6
+
7
+ When an endpoint pages through results with a query parameter, set [`infinite`](https://kubb.dev/extensions/kubb-labs/plugin-vue-query/options#infinite) next to `hooks: true`. Only operations that declare `infinite.queryParam` get an infinite composable, and the composable sends each page param as that parameter:
8
+
9
+ ::code-group
10
+
11
+ ```typescript [kubb.config.ts]
12
+ import { defineConfig } from 'kubb/config'
13
+ import { pluginTs } from '@kubb/plugin-ts'
14
+ import { pluginFetch } from '@kubb/plugin-fetch'
15
+ import { pluginVueQuery } from '@kubb/plugin-vue-query'
16
+
17
+ export default defineConfig({
18
+ input: './petStore.yaml',
19
+ output: { path: './src/gen' },
20
+ plugins: [
21
+ pluginTs(),
22
+ pluginFetch(),
23
+ pluginVueQuery({
24
+ hooks: true,
25
+ infinite: { queryParam: 'page', initialPageParam: 0, nextParam: 'pagination.next.cursor' },
26
+ }),
27
+ ],
28
+ })
29
+ ```
30
+
31
+ ```typescript [Generated]
32
+ // src/gen/hooks/useFindPetsByTagsInfinite.ts, types left out
33
+ export const findPetsByTagsInfiniteQueryKey = ({ query }: { query?: MaybeRefOrGetter<Omit<FindPetsByTagsOptions, 'headers'>['query']> } = {}) =>
34
+ [{ url: '/pet/findByTags', infinite: true }, ...(query ? [query] : [])] as const
35
+
36
+ export function findPetsByTagsInfiniteQueryOptions({ query }: { query?: MaybeRefOrGetter<FindPetsByTagsOptions['query']> } = {}, config = {}) {
37
+ const queryKey = findPetsByTagsInfiniteQueryKey({ query })
38
+ return infiniteQueryOptions({
39
+ queryKey,
40
+ queryFn: async ({ signal, pageParam }) => {
41
+ return findPetsByTags({ ...config, query: { ...toValue(query), page: pageParam }, signal: config.signal ?? signal, throwOnError: true }).unwrap()
42
+ },
43
+ initialPageParam: 0,
44
+ getNextPageParam: (lastPage) => lastPage?.['pagination']?.['next']?.['cursor'],
45
+ })
46
+ }
47
+ ```
48
+
49
+ ```typescript [Usage]
50
+ import { ref } from 'vue'
51
+ import { useFindPetsByTagsInfinite } from './gen/hooks/useFindPetsByTagsInfinite'
52
+
53
+ const tags = ref(['dog'])
54
+ const { data, fetchNextPage, hasNextPage } = useFindPetsByTagsInfinite({ query: () => ({ tags: tags.value }) })
55
+ ```
56
+
57
+ ::
58
+
59
+ - Give `initialPageParam` the type of the query parameter.
60
+ - The infinite key adds `infinite: true`, so it never shares a cache entry with the plain query. See [TanStack Query keys](https://kubb.dev/extensions/kubb-labs/plugin-vue-query/guides/query-keys).
61
+ - A ref or getter in `query` updates the key, so a change starts again from the first page.
62
+
63
+ ## Read the next page from the response
64
+
65
+ The generated `getNextPageParam` comes from the first of these options you set:
66
+
67
+ | Option | Generated `getNextPageParam` |
68
+ | ------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
69
+ | [`getNextPageParam`](https://kubb.dev/extensions/kubb-labs/plugin-vue-query/options#infinitegetnextpageparam) | Your function's source, copied as written. It cannot use variables from the config file. |
70
+ | [`nextParam`](https://kubb.dev/extensions/kubb-labs/plugin-vue-query/options#infinitenextparam) | Reads that path on the last page, such as `lastPage?.['pagination']?.['next']?.['cursor']`. |
71
+ | [`cursorParam`](https://kubb.dev/extensions/kubb-labs/plugin-vue-query/options#infinitecursorparam) | Deprecated. Reads that top-level field. |
72
+ | None | Counts pages up from `initialPageParam` until a page is an empty array. |
73
+
74
+ `getPreviousPageParam`, `previousParam`, and `cursorParam` set the previous page in the same order. With [`returnType: 'full'`](https://kubb.dev/extensions/kubb-labs/plugin-vue-query/options#returntype), the `nextParam` and `cursorParam` accessors read from `lastPage.data`.
75
+
76
+ ## hasNextPage never turns false
77
+
78
+ Generation prints this warning for the operation:
79
+
80
+ ```text
81
+ findPetsByTags: the default infinite page params expect an array response and never end for this one. Set `infinite.getNextPageParam` (or `nextParam`) to read the next page from the response.
82
+ ```
83
+
84
+ Without `getNextPageParam`, `nextParam`, or `cursorParam`, the composable counts pages up from `initialPageParam` until a page is an empty array. That works only for array responses, so generation warns for any other response. It skips the warning when `previousParam` or `getPreviousPageParam` is set, though the count still never ends.
85
+
86
+ To fix it, set `nextParam` to the cursor path, or `getNextPageParam` when you must compute the next page.
87
+
88
+ Next, see every [`infinite` option](https://kubb.dev/extensions/kubb-labs/plugin-vue-query/options#infinite), including `definePageParam` for a typed `getNextPageParam`.
@@ -0,0 +1,113 @@
1
+ # TanStack Query keys
2
+
3
+ See the query key each generated Vue Query composable uses, invalidate or read the cache with it, and add your own prefix to the default key.
4
+
5
+ ## The default query key
6
+
7
+ When you call `invalidateQueries`, `getQueryData`, or `setQueryData`, take the key from the `<operation>QueryKey` helper in each composable file. It builds `[{ url, params }, query, body]`:
8
+
9
+ ::code-group
10
+
11
+ ```typescript [Generated]
12
+ // src/gen/hooks/useGetPetById.ts
13
+ export const getPetByIdQueryKey = ({ path }: { path: MaybeRefOrGetter<Omit<GetPetByIdOptions, 'headers'>['path']> }) =>
14
+ [{ url: '/pet/:petId', params: path }] as const
15
+
16
+ // src/gen/hooks/useFindPetsByTags.ts
17
+ export const findPetsByTagsQueryKey = ({ query }: { query?: MaybeRefOrGetter<Omit<FindPetsByTagsOptions, 'headers'>['query']> } = {}) =>
18
+ [{ url: '/pet/findByTags' }, ...(query ? [query] : [])] as const
19
+ ```
20
+
21
+ ```typescript [Usage]
22
+ import { getPetByIdQueryKey } from './gen/hooks/useGetPetById'
23
+ import { findPetsByTagsQueryKey } from './gen/hooks/useFindPetsByTags'
24
+ import { queryClient } from './queryClient'
25
+
26
+ getPetByIdQueryKey({ path: { petId: 1 } }) // [{ url: '/pet/:petId', params: { petId: 1 } }]
27
+ findPetsByTagsQueryKey({ query: { tags: ['dog'] } }) // [{ url: '/pet/findByTags' }, { tags: ['dog'] }]
28
+
29
+ const pet = queryClient.getQueryData(getPetByIdQueryKey({ path: { petId: 1 } }))
30
+ ```
31
+
32
+ ::
33
+
34
+ - `url` is the spec path with `:name` placeholders, such as `'/pet/:petId'`.
35
+ - `params` holds the path parameters, when the path has any.
36
+ - `query` and `body` follow when the operation has them and the call passes them.
37
+ - Headers and cookies stay out of the key.
38
+ - Infinite variants add `infinite: true` to the first entry, so they never share a cache entry with the plain query.
39
+ - Each composable returns the key it used as `queryKey` on its result.
40
+
41
+ ## Keys with refs and getters
42
+
43
+ When you pass a ref or a getter to a composable, the key holds it as passed. Vue Query unwraps refs and getters inside `queryKey`, so a change updates the key and fetches again.
44
+
45
+ > [!NOTE]
46
+ > `getQueryData` and `setQueryData` take the key array itself and do not unwrap getters. Pass plain values or refs to the key helper there.
47
+
48
+ ## Invalidate every call of an operation
49
+
50
+ TanStack Query matches a key by its prefix, and an object entry by the fields you pass. A key built without `query` matches every cached call of that operation with the same path parameters, infinite ones included:
51
+
52
+ ```typescript
53
+ queryClient.invalidateQueries({ queryKey: findPetsByTagsQueryKey() })
54
+ ```
55
+
56
+ ## Mutation keys
57
+
58
+ Each mutation gets a `<operation>MutationKey` helper that returns `[{ url }]`, for filters such as `useIsMutating` or `useMutationState`:
59
+
60
+ ::code-group
61
+
62
+ ```typescript [Generated]
63
+ // src/gen/hooks/useUpdatePet.ts
64
+ export const updatePetMutationKey = () => [{ url: '/pet' }] as const
65
+ ```
66
+
67
+ ```typescript [Usage]
68
+ import { useIsMutating } from '@tanstack/vue-query'
69
+ import { updatePetMutationKey } from './gen/hooks/useUpdatePet'
70
+
71
+ const saving = useIsMutating({ mutationKey: updatePetMutationKey() })
72
+ ```
73
+
74
+ ::
75
+
76
+ ## Extend the default key
77
+
78
+ When you need your own entry, such as an API version, set [`queryKey`](https://kubb.dev/extensions/kubb-labs/plugin-vue-query/options#querykey) and spread `queryKeyTransformer`. Do not read single entries of its result: they can change between releases.
79
+
80
+ > [!WARNING]
81
+ > Returned strings are copied into the generated code as written. Wrap a string literal in `JSON.stringify(...)`.
82
+
83
+ ::code-group
84
+
85
+ ```typescript [kubb.config.ts]
86
+ import { defineConfig } from 'kubb/config'
87
+ import { pluginTs } from '@kubb/plugin-ts'
88
+ import { pluginFetch } from '@kubb/plugin-fetch'
89
+ import { pluginVueQuery, queryKeyTransformer } from '@kubb/plugin-vue-query'
90
+
91
+ export default defineConfig({
92
+ input: './petStore.yaml',
93
+ output: { path: './src/gen' },
94
+ plugins: [
95
+ pluginTs(),
96
+ pluginFetch(),
97
+ pluginVueQuery({
98
+ queryKey: (props) => [JSON.stringify('v2'), ...queryKeyTransformer(props)],
99
+ }),
100
+ ],
101
+ })
102
+ ```
103
+
104
+ ```typescript [Generated]
105
+ export const getPetByIdQueryKey = ({ path }: { path: MaybeRefOrGetter<Omit<GetPetByIdOptions, 'headers'>['path']> }) =>
106
+ ["v2", { url: '/pet/:petId', params: path }] as const
107
+ ```
108
+
109
+ ::
110
+
111
+ The builder also gets the `variant`, so it can return a different key for infinite composables. [`mutationKey`](https://kubb.dev/extensions/kubb-labs/plugin-vue-query/options#mutationkey) works the same way with `mutationKeyTransformer`.
112
+
113
+ Next, [generate infinite queries](https://kubb.dev/extensions/kubb-labs/plugin-vue-query/guides/infinite-queries) for paginated endpoints.
package/docs/options.md CHANGED
@@ -1,32 +1,43 @@
1
1
  # Options
2
2
 
3
- Pass these options to `pluginVueQuery()`. Shared options link to [Shared plugin options](https://kubb.dev/docs/5.x/reference/plugin-options) for details.
3
+ Pass these options to `pluginVueQuery()`. Shared options link to [Shared plugin options](https://kubb.dev/docs/5.x/reference/plugin-options).
4
4
 
5
5
  ## Options overview
6
6
 
7
- | Option | Purpose | Default |
8
- | ------------------------------------------------------------------------- | ---------------------------------------------------------------------- | ------------------------------------------------------------------------------------ |
9
- | [`output`](https://kubb.dev/docs/5.x/reference/plugin-options#output) | Where files are written: `path`, `mode`, `barrel`, `banner`, `footer`. | `{ path: 'hooks', barrel: { type: 'named' } }` |
10
- | [`group`](https://kubb.dev/docs/5.x/reference/plugin-options#group) | Split output by tag or path: `type`, `name`. | None |
11
- | [`client`](#client) | Which registered client plugin the composables call. | Auto-detected |
12
- | [`returnType`](#returntype) | Shape of the value the composables resolve to. | `'data'` |
13
- | [`infinite`](#infinite) | Add `useInfiniteQuery` composables for paginated reads. | `false` |
14
- | [`query`](#query) | Configure or disable query composables. | `{ methods: ['GET', 'QUERY'], importPath: '@tanstack/vue-query' }` |
15
- | [`queryKey`](#querykey) | Build the `queryKey` for each query composable. | Exported `queryKeyTransformer` |
16
- | [`mutation`](#mutation) | Configure or disable mutation composables. | `{ methods: ['POST', 'PUT', 'PATCH', 'DELETE'], importPath: '@tanstack/vue-query' }` |
17
- | [`mutationKey`](#mutationkey) | Build the `mutationKey` for each mutation composable. | Exported `mutationKeyTransformer` |
18
- | [`hooks`](#hooks) | Emit `use*` composables on top of the factory helpers. | `false` |
19
- | [`include`](https://kubb.dev/docs/5.x/reference/plugin-options#include) | Keep only operations that match. | None |
20
- | [`exclude`](https://kubb.dev/docs/5.x/reference/plugin-options#exclude) | Skip operations that match. | `[]` |
21
- | [`override`](https://kubb.dev/docs/5.x/reference/plugin-options#override) | Apply different options per pattern. | `[]` |
22
- | [`resolver`](#resolver) | Customize generated names and file paths. | `resolverVueQuery` |
23
- | [`macros`](https://kubb.dev/docs/5.x/reference/plugin-options#macros) | Rewrite AST nodes before printing. | `[]` |
7
+ | Option | Purpose | Default |
8
+ | ------------------------------------------------------------------------- | -------------------------------------------------------- | ------------------------------------------------------------------------------------ |
9
+ | [`client`](#client) | Client plugin the composables call. | Auto-detected |
10
+ | [`returnType`](#returntype) | What the composables resolve to. | `'data'` |
11
+ | [`hooks`](#hooks) | Emit `use*` composables on top of the factories. | `false` |
12
+ | [`query`](#query) | Which methods become queries, and the TanStack import. | `{ methods: ['GET', 'QUERY'], importPath: '@tanstack/vue-query' }` |
13
+ | [`query.methods`](#querymethods) | Methods that become queries. | `['GET', 'QUERY']` |
14
+ | [`query.importPath`](#queryimportpath) | Import path of the query helpers. | `'@tanstack/vue-query'` |
15
+ | [`queryKey`](#querykey) | Build the `queryKey` of each query. | `queryKeyTransformer` |
16
+ | [`mutation`](#mutation) | Which methods become mutations, and the TanStack import. | `{ methods: ['POST', 'PUT', 'PATCH', 'DELETE'], importPath: '@tanstack/vue-query' }` |
17
+ | [`mutation.methods`](#mutationmethods) | Methods that become mutations. | `['POST', 'PUT', 'PATCH', 'DELETE']` |
18
+ | [`mutation.importPath`](#mutationimportpath) | Import path of the mutation composables. | `'@tanstack/vue-query'` |
19
+ | [`mutationKey`](#mutationkey) | Build the `mutationKey` of each mutation. | `mutationKeyTransformer` |
20
+ | [`infinite`](#infinite) | Generate infinite queries for pagination. | `false` |
21
+ | [`infinite.queryParam`](#infinitequeryparam) | Query parameter for the page cursor. | `'id'` |
22
+ | [`infinite.initialPageParam`](#infiniteinitialpageparam) | First `pageParam`. | `0` |
23
+ | [`infinite.nextParam`](#infinitenextparam) | Path to the next cursor. | `null` |
24
+ | [`infinite.previousParam`](#infinitepreviousparam) | Path to the previous cursor. | `null` |
25
+ | [`infinite.getNextPageParam`](#infinitegetnextpageparam) | Compute the next page param. | `null` |
26
+ | [`infinite.getPreviousPageParam`](#infinitegetpreviouspageparam) | Compute the previous page param. | `null` |
27
+ | [`infinite.cursorParam`](#infinitecursorparam) | Deprecated cursor field. | `null` |
28
+ | [`output`](https://kubb.dev/docs/5.x/reference/plugin-options#output) | Where files are written. | `{ path: 'hooks', barrel: { type: 'named' } }` |
29
+ | [`group`](https://kubb.dev/docs/5.x/reference/plugin-options#group) | Split output by tag or path. | None |
30
+ | [`include`](https://kubb.dev/docs/5.x/reference/plugin-options#include) | Keep only operations that match. | None |
31
+ | [`exclude`](https://kubb.dev/docs/5.x/reference/plugin-options#exclude) | Skip operations that match. | `[]` |
32
+ | [`override`](https://kubb.dev/docs/5.x/reference/plugin-options#override) | Apply different options per pattern. | `[]` |
33
+ | [`resolver`](#resolver) | Customize generated names and file paths. | `resolverVueQuery` |
34
+ | [`macros`](https://kubb.dev/docs/5.x/reference/plugin-options#macros) | Rewrite AST nodes before printing. | `[]` |
24
35
 
25
36
  ## Option details
26
37
 
27
38
  ### client
28
39
 
29
- Selects which registered client plugin the composables call. A single registered client is auto-detected. Set `client` when several are registered.
40
+ The client plugin the composables call. Kubb detects a lone client plugin, so set `client` only when several are registered. Generation fails when none is.
30
41
 
31
42
  | | |
32
43
  | -------- | -------------------------------- |
@@ -36,163 +47,62 @@ Selects which registered client plugin the composables call. A single registered
36
47
  ::field-group
37
48
 
38
49
  :::field{name="'fetch'"}
39
- Calls the operations generated by [`@kubb/plugin-fetch`](https://kubb.dev/extensions/kubb-labs/plugin-fetch).
50
+ Calls [`@kubb/plugin-fetch`](https://kubb.dev/extensions/kubb-labs/plugin-fetch).
40
51
  :::
41
52
 
42
53
  :::field{name="'axios'"}
43
- Calls the operations generated by [`@kubb/plugin-axios`](https://kubb.dev/extensions/kubb-labs/plugin-axios).
54
+ Calls [`@kubb/plugin-axios`](https://kubb.dev/extensions/kubb-labs/plugin-axios).
44
55
  :::
45
56
 
46
57
  :::field{name="'client'"}
47
- Calls the operations generated by [`@kubb/plugin-client`](https://kubb.dev/extensions/kubb-labs/plugin-client). The client module must also export the `RequestConfig` and `ResponseErrorConfig` types.
58
+ Calls [`@kubb/plugin-client`](https://kubb.dev/extensions/kubb-labs/plugin-client). Your client module must also export `RequestConfig` and `ResponseErrorConfig`.
48
59
  :::
49
60
 
50
61
  ::
51
62
 
52
63
  ### returnType
53
64
 
54
- Shape of the value the generated composables resolve to.
65
+ What the composables resolve to.
55
66
 
56
67
  | | |
57
68
  | -------- | ------------------ |
58
- | Type | `'full' \| 'data'` |
69
+ | Type | `'data' \| 'full'` |
59
70
  | Required | `false` |
60
71
  | Default | `'data'` |
61
72
 
62
73
  ::field-group
63
74
 
64
- :::field{name="'full'"}
65
- Returns the client's whole `RequestResult` (`{ status, data, error, contentType, headers, request, response }`), so a composable can read the status and the response headers next to `data`. Infinite queries read the page cursor from `lastPage.data`. Needs a client plugin whose own `returnType` is `'full'` or `'plain'`. With a client `returnType: 'data'`, generation stops with an error.
75
+ :::field{name="'data'"}
76
+ Resolves to the success body.
66
77
  :::
67
78
 
68
- :::field{name="'data'"}
69
- Returns the success body.
79
+ :::field{name="'full'"}
80
+ Resolves to the client's whole `RequestResult`, so a composable can read the status and headers. Needs a client plugin with `returnType` `'full'` or `'plain'`, or generation fails.
70
81
  :::
71
82
 
72
83
  ::
73
84
 
74
- ```ts
85
+ ```typescript
75
86
  pluginVueQuery({ returnType: 'full' })
76
87
 
88
+ // with integerType: 'number' on the adapter
77
89
  const { data: result } = useGetPetById({ path: { petId: 1 } })
78
-
79
90
  const etag = result.value?.response.headers.get('ETag')
80
- const pet = result.value?.data
81
- ```
82
-
83
- The examples set [`integerType: 'number'`](https://kubb.dev/extensions/kubb-labs/adapter-oas/options#integertype) on the adapter, so an `int64` id such as `petId` is a `number`. With the default it is a `bigint` and the call takes `1n`.
84
-
85
- ### infinite
86
-
87
- Adds `infiniteQueryOptions` and `useInfiniteQuery` for operations that declare the query parameter named in `infinite.queryParam`. Needs [`hooks: true`](#hooks).
88
-
89
- | | |
90
- | -------- | ---------------------------- |
91
- | Type | `Partial<Infinite> \| false` |
92
- | Required | `false` |
93
- | Default | `false` |
94
-
95
- ```typescript [infinite: {}, hooks: true]
96
- export function getPetsInfiniteQueryOptions(/* ... */) {
97
- return infiniteQueryOptions({ queryKey, queryFn, initialPageParam, getNextPageParam })
98
- }
99
-
100
- export function useGetPetsInfinite(/* ... */) {
101
- return useInfiniteQuery(getPetsInfiniteQueryOptions(/* ... */))
102
- }
103
91
  ```
104
92
 
105
- #### infinite.queryParam
106
-
107
- Name of the query parameter that holds the page cursor.
108
-
109
- | | |
110
- | -------- | -------- |
111
- | Type | `string` |
112
- | Required | `false` |
113
- | Default | `'id'` |
114
-
115
- #### infinite.initialPageParam
93
+ ### hooks
116
94
 
117
- Initial value for `pageParam` on the first fetch.
95
+ Set `true` to generate `useQuery` and `useMutation` composables on top of the `queryOptions` and key helpers. [Call operations](https://kubb.dev/extensions/kubb-labs/plugin-vue-query/guides/calling-operations#what-each-plugin-generates) lists every export.
118
96
 
119
97
  | | |
120
98
  | -------- | --------- |
121
- | Type | `unknown` |
99
+ | Type | `boolean` |
122
100
  | Required | `false` |
123
- | Default | `0` |
124
-
125
- #### infinite.nextParam
126
-
127
- Path to the next-page cursor on the response, as dot notation (`'pagination.next.id'`) or array form (`['pagination', 'next', 'id']`).
128
-
129
- | | |
130
- | -------- | --------------------------------- |
131
- | Type | `string \| Array<string> \| null` |
132
- | Required | `false` |
133
- | Default | `null` |
134
-
135
- #### infinite.previousParam
136
-
137
- Path to the previous-page cursor on the response, in the same dot or array form.
138
-
139
- | | |
140
- | -------- | --------------------------------- |
141
- | Type | `string \| Array<string> \| null` |
142
- | Required | `false` |
143
- | Default | `null` |
144
-
145
- #### infinite.cursorParam
146
-
147
- Deprecated name of a top-level response field that holds the cursor, read for both `getNextPageParam` and `getPreviousPageParam` when set. Dot paths are not supported. Use `nextParam` and `previousParam` instead.
148
-
149
- | | |
150
- | -------- | ---------------- |
151
- | Type | `string \| null` |
152
- | Required | `false` |
153
- | Default | `null` |
154
-
155
- #### infinite.getNextPageParam
156
-
157
- Source code for TanStack Query's `getNextPageParam`, copied into the generated code as written, such as `'(lastPage) => (lastPage.hasNext ? lastPage.number + 1 : undefined)'`. Pass a string or a function. Use it when the next page must be computed instead of read from a field. Takes precedence over `nextParam` and `cursorParam`.
158
-
159
- | | |
160
- | -------- | ------------------------------- |
161
- | Type | `string \| PageParamFn \| null` |
162
- | Required | `false` |
163
- | Default | `null` |
164
-
165
- `definePageParam` types the page and the page parameter, and returns the function's source. A plain function works too. Only the source is copied, so the function cannot reference variables from the config file.
166
-
167
- ```typescript [kubb.config.ts]
168
- import { definePageParam, pluginVueQuery } from '@kubb/plugin-vue-query'
169
-
170
- type PetsPage = { hasNext: boolean; number: number }
171
-
172
- pluginVueQuery({
173
- hooks: true,
174
- infinite: {
175
- queryParam: 'page',
176
- getNextPageParam: definePageParam<PetsPage, number>((lastPage) => (lastPage.hasNext ? lastPage.number + 1 : undefined)),
177
- },
178
- })
179
- ```
180
-
181
- Without `getNextPageParam`, `nextParam` or `cursorParam`, the composable counts pages up from `initialPageParam` until a page is an empty array. Counting works only for array responses, so generation warns for any other response.
182
-
183
- #### infinite.getPreviousPageParam
184
-
185
- Source code for TanStack Query's `getPreviousPageParam`, copied into the generated code as written. Takes a string or a function, like `getNextPageParam`. Takes precedence over `previousParam` and `cursorParam`.
186
-
187
- | | |
188
- | -------- | ------------------------------- |
189
- | Type | `string \| PageParamFn \| null` |
190
- | Required | `false` |
191
- | Default | `null` |
101
+ | Default | `false` |
192
102
 
193
103
  ### query
194
104
 
195
- Decides which operations are treated as queries. The plugin generates a `queryOptions` factory for each match by default. Pass `false` to skip, or set [`hooks`](#hooks) to also emit `useQuery`.
105
+ Which operations become queries and where TanStack Query is imported from. `false` skips query output.
196
106
 
197
107
  | | |
198
108
  | -------- | ------------------------------------------------------------------ |
@@ -202,7 +112,7 @@ Decides which operations are treated as queries. The plugin generates a `queryOp
202
112
 
203
113
  #### query.methods
204
114
 
205
- HTTP methods treated as queries. A matching operation generates a `queryOptions` factory instead of a mutation.
115
+ HTTP methods treated as queries. A method in neither list gets no helper, so keep `'QUERY'` when you replace it.
206
116
 
207
117
  | | |
208
118
  | -------- | ------------------ |
@@ -210,11 +120,9 @@ HTTP methods treated as queries. A matching operation generates a `queryOptions`
210
120
  | Required | `false` |
211
121
  | Default | `['GET', 'QUERY']` |
212
122
 
213
- Operations whose method is in neither `query.methods` nor `mutation.methods` get no hook. Keep `'QUERY'` here when overriding the list, or QUERY operations are skipped.
214
-
215
123
  #### query.importPath
216
124
 
217
- Module specifier for the generated `import { queryOptions } from '...'`.
125
+ Module for `queryOptions`, `useQuery`, and their infinite variants, such as a wrapper that sets a default `QueryClient`.
218
126
 
219
127
  | | |
220
128
  | -------- | ----------------------- |
@@ -224,37 +132,28 @@ Module specifier for the generated `import { queryOptions } from '...'`.
224
132
 
225
133
  ### queryKey
226
134
 
227
- Builds the `queryKey` for each query composable. The callback receives the operation `node`, the active `casing` and the `variant` (`'query'` or `'infiniteQuery'`) and returns the key array. Strings are copied into the generated code as written, so wrap a string literal in `JSON.stringify(...)`. The default adds `infinite: true` to infinite keys so they never share a cache entry with the plain query.
135
+ Builds each query's `queryKey` from the operation `node` and the `variant`: `'query'` or `'infiniteQuery'`. The default key is `[{ url, params }, query, body]`.
228
136
 
229
137
  | | |
230
138
  | -------- | ------------------------------------------------------ |
231
139
  | Type | `(props: { node, casing, variant }) => Array<unknown>` |
232
140
  | Required | `false` |
233
- | Default | Exported `queryKeyTransformer` |
234
-
235
- ::code-group
236
-
237
- ```typescript [queryKey builder]
238
- queryKey: ({ node, variant }) => [JSON.stringify({ variant, operationId: node.operationId })]
239
- ```
141
+ | Default | `queryKeyTransformer` |
240
142
 
241
- ```typescript [Generated output]
242
- export const getUserByNameQueryKey = ({ path }: { path: MaybeRefOrGetter<Omit<GetUserByNameOptions, 'headers'>['path']> }) => [{"variant":"query","operationId":"getUserByName"}] as const
243
- ```
244
-
245
- ::
143
+ > [!WARNING]
144
+ > Returned strings are copied into the generated code as written, so wrap a string literal in `JSON.stringify(...)`.
246
145
 
247
- To extend the default key instead of replacing it, import `queryKeyTransformer` and spread its result. The default segments can change between releases, so spread them instead of reading single entries.
146
+ To extend the default, spread it. See [TanStack Query keys](https://kubb.dev/extensions/kubb-labs/plugin-vue-query/guides/query-keys).
248
147
 
249
148
  ```typescript
250
149
  import { queryKeyTransformer } from '@kubb/plugin-vue-query'
251
150
 
252
- queryKey: (props) => [JSON.stringify(props.node.operationId), ...queryKeyTransformer(props)]
151
+ queryKey: (props) => [JSON.stringify('v2'), ...queryKeyTransformer(props)]
253
152
  ```
254
153
 
255
154
  ### mutation
256
155
 
257
- Decides which operations are treated as mutations. The plugin generates a `mutationKey` helper for each match by default. Pass `false` to skip, or set [`hooks`](#hooks) to also emit `useMutation`.
156
+ Which operations become mutations and where TanStack Query is imported from. `false` skips mutation output.
258
157
 
259
158
  | | |
260
159
  | -------- | ------------------------------------------------------------------------------------ |
@@ -264,7 +163,7 @@ Decides which operations are treated as mutations. The plugin generates a `mutat
264
163
 
265
164
  #### mutation.methods
266
165
 
267
- HTTP methods treated as mutations. A matching operation generates mutation output instead of a query.
166
+ HTTP methods treated as mutations. A method also in `query.methods` stays a query.
268
167
 
269
168
  | | |
270
169
  | -------- | ------------------------------------ |
@@ -274,7 +173,7 @@ HTTP methods treated as mutations. A matching operation generates mutation outpu
274
173
 
275
174
  #### mutation.importPath
276
175
 
277
- Module specifier for the generated `import { useMutation } from '...'`, emitted when [`hooks`](#hooks) is set.
176
+ Module for `useMutation`. Only used with [`hooks: true`](#hooks).
278
177
 
279
178
  | | |
280
179
  | -------- | ----------------------- |
@@ -284,35 +183,123 @@ Module specifier for the generated `import { useMutation } from '...'`, emitted
284
183
 
285
184
  ### mutationKey
286
185
 
287
- Builds the `mutationKey` for each mutation composable, useful for batching invalidations. The builder takes the same props as `queryKey` with `variant: 'mutation'` and inlines strings the same way, so wrap literals in `JSON.stringify(...)`.
186
+ Builds each mutation's `mutationKey`, for batched invalidations. It works like [`queryKey`](#querykey) with `variant: 'mutation'`. The default key is `[{ url }]`.
288
187
 
289
188
  | | |
290
189
  | -------- | ------------------------------------------------------ |
291
190
  | Type | `(props: { node, casing, variant }) => Array<unknown>` |
292
191
  | Required | `false` |
293
- | Default | Exported `mutationKeyTransformer` |
294
-
295
- Extend the default the same way with `mutationKeyTransformer`:
192
+ | Default | `mutationKeyTransformer` |
296
193
 
297
194
  ```typescript
298
195
  import { mutationKeyTransformer } from '@kubb/plugin-vue-query'
299
196
 
300
- mutationKey: (props) => [JSON.stringify(props.node.operationId), ...mutationKeyTransformer(props)]
197
+ mutationKey: (props) => [JSON.stringify('v2'), ...mutationKeyTransformer(props)]
301
198
  ```
302
199
 
303
- ### hooks
200
+ ### infinite
201
+
202
+ Adds `infiniteQueryOptions` and `useInfiniteQuery` to each query operation that takes the [`infinite.queryParam`](#infinitequeryparam) parameter. Needs [`hooks: true`](#hooks).
203
+
204
+ | | |
205
+ | -------- | ---------------------------- |
206
+ | Type | `Partial<Infinite> \| false` |
207
+ | Required | `false` |
208
+ | Default | `false` |
209
+
210
+ > [!WARNING]
211
+ > Set `nextParam` or `getNextPageParam`. Otherwise `hasNextPage` never turns false for a non-array response. See [Infinite queries](https://kubb.dev/extensions/kubb-labs/plugin-vue-query/guides/infinite-queries#hasnextpage-never-turns-false).
212
+
213
+ #### infinite.queryParam
214
+
215
+ Query parameter that carries the page cursor.
216
+
217
+ | | |
218
+ | -------- | -------- |
219
+ | Type | `string` |
220
+ | Required | `false` |
221
+ | Default | `'id'` |
222
+
223
+ #### infinite.initialPageParam
304
224
 
305
- Controls whether `use*` composables are emitted. The default `false` writes only the `queryOptions`, `queryKey`, and `mutationKey` factory helpers. Set `true` to also generate `useQuery`, `useInfiniteQuery`, and `useMutation`.
225
+ `pageParam` of the first fetch. Give it the type of the query parameter.
306
226
 
307
227
  | | |
308
228
  | -------- | --------- |
309
- | Type | `boolean` |
229
+ | Type | `unknown` |
310
230
  | Required | `false` |
311
- | Default | `false` |
231
+ | Default | `0` |
232
+
233
+ #### infinite.nextParam
234
+
235
+ Path to the next cursor on the response, in dot notation (`'pagination.next.id'`) or array form (`['pagination', 'next', 'id']`).
236
+
237
+ | | |
238
+ | -------- | --------------------------------- |
239
+ | Type | `string \| Array<string> \| null` |
240
+ | Required | `false` |
241
+ | Default | `null` |
242
+
243
+ #### infinite.previousParam
244
+
245
+ Path to the previous cursor, in the same forms as `nextParam`.
246
+
247
+ | | |
248
+ | -------- | --------------------------------- |
249
+ | Type | `string \| Array<string> \| null` |
250
+ | Required | `false` |
251
+ | Default | `null` |
252
+
253
+ #### infinite.getNextPageParam
254
+
255
+ Source of TanStack Query's `getNextPageParam`, for a next page you must compute. Pass a string, a function, or `definePageParam`, which types the page and the page parameter.
256
+
257
+ | | |
258
+ | -------- | ------------------------------- |
259
+ | Type | `string \| PageParamFn \| null` |
260
+ | Required | `false` |
261
+ | Default | `null` |
262
+
263
+ > [!NOTE]
264
+ > Only the function's source is copied, so it cannot use variables from the config file.
265
+
266
+ ```typescript [kubb.config.ts]
267
+ import { definePageParam, pluginVueQuery } from '@kubb/plugin-vue-query'
268
+
269
+ type PetsPage = { hasNext: boolean; number: number }
270
+
271
+ pluginVueQuery({
272
+ hooks: true,
273
+ infinite: {
274
+ queryParam: 'page',
275
+ getNextPageParam: definePageParam<PetsPage, number>((lastPage) => (lastPage.hasNext ? lastPage.number + 1 : undefined)),
276
+ },
277
+ })
278
+ ```
279
+
280
+ #### infinite.getPreviousPageParam
281
+
282
+ Source of TanStack Query's `getPreviousPageParam`, in the same forms as `getNextPageParam`.
283
+
284
+ | | |
285
+ | -------- | ------------------------------- |
286
+ | Type | `string \| PageParamFn \| null` |
287
+ | Required | `false` |
288
+ | Default | `null` |
289
+
290
+ #### infinite.cursorParam
291
+
292
+ Deprecated. Use `nextParam` and `previousParam`. A top-level response field, not a dot path, that holds the cursor for both directions.
293
+
294
+ | | |
295
+ | -------- | ---------------- |
296
+ | Type | `string \| null` |
297
+ | Required | `false` |
298
+ | Default | `null` |
312
299
 
313
300
  ### resolver
314
301
 
315
- Overrides generated file and symbol names. Omitted members keep `resolverVueQuery`. The shared members (`name`, `file`, `imports`) and the `this` context are described under [`resolver`](https://kubb.dev/docs/5.x/reference/plugin-options#resolver).
302
+ Overrides generated names. Members you leave out keep `resolverVueQuery`. See [`resolver`](https://kubb.dev/docs/5.x/reference/plugin-options#resolver) for the shared members.
316
303
 
317
304
  | | |
318
305
  | -------- | --------------------------------- |
@@ -325,15 +312,16 @@ Overrides generated file and symbol names. Omitted members keep `resolverVueQuer
325
312
  type ResolverVueQueryPatch = {
326
313
  // plus the shared name, file, and imports members
327
314
  query?: {
328
- name?(node: OperationNode): string
329
- optionsName?(node: OperationNode): string
330
- keyName?(node: OperationNode): string
331
- keyTypeName?(node: OperationNode): string
315
+ name?(node: OperationNode): string // 'useGetPetById'
316
+ optionsName?(node: OperationNode): string // 'getPetByIdQueryOptions'
317
+ keyName?(node: OperationNode): string // 'getPetByIdQueryKey'
318
+ keyTypeName?(node: OperationNode): string // 'GetPetByIdQueryKey'
332
319
  }
333
- infiniteQuery?: { /* same members as query */ }
320
+ // same members, with an Infinite suffix
321
+ infiniteQuery?: ResolverVueQueryPatch['query']
334
322
  mutation?: {
335
- name?(node: OperationNode): string
336
- keyName?(node: OperationNode): string
323
+ name?(node: OperationNode): string // 'useUpdatePet'
324
+ keyName?(node: OperationNode): string // 'updatePetMutationKey'
337
325
  }
338
326
  }
339
327
  ```
package/docs/overview.md CHANGED
@@ -1,27 +1,29 @@
1
1
  # Vue Query
2
2
 
3
- The Vue Query plugin generates TanStack Query helpers for Vue from your OpenAPI spec. By default you get `queryOptions` factories with their query keys, plus a key for each mutation. Set `hooks: true` to also get `useQuery` and `useMutation` composables with reactive parameters.
3
+ The Vue Query plugin generates TanStack Query `queryOptions` factories, query and mutation keys, and optional composables from your OpenAPI spec.
4
4
 
5
- The plugin ships no HTTP client. Each helper calls a function generated by a client plugin.
5
+ - `hooks: true` adds `useQuery` and `useMutation` composables that take reactive parameters, with infinite variants on request.
6
+ - The plugin ships no HTTP client. Each helper calls a function from your client plugin.
6
7
 
7
8
  ## Setup
8
9
 
9
- - Add `@kubb/plugin-ts`, or `pluginZod({ inferred: 'codec' })` for codec types, and a client plugin: `@kubb/plugin-fetch`, `@kubb/plugin-axios`, or `@kubb/plugin-client`. Leave `sdk` unset on the client plugin.
10
- - Install `@tanstack/vue-query` 5.41 or a later v5 release and `vue` 3.3 or a later v3 release in the app that uses the generated code.
11
- - Configure validation on the client plugin, not here.
10
+ - Add `@kubb/plugin-ts`, or `pluginZod({ inferred: 'codec' })` with `zod` v4 in the app.
11
+ - Add one client plugin: `@kubb/plugin-fetch`, `@kubb/plugin-axios`, or `@kubb/plugin-client`. Leave `sdk` unset on it.
12
+ - Install `@tanstack/vue-query` 5.41 or a later v5 release and `vue` 3.3 or later in the app.
13
+ - Set the base URL, auth, and validation on the client plugin. With `@kubb/plugin-client`, your client module owns them.
12
14
 
13
15
  ## Options worth knowing
14
16
 
15
- - `client` picks `fetch`, `axios`, or `client` when more than one client plugin is registered. A single client plugin is detected automatically.
16
- - `hooks` adds the `use*` composables on top of the query option factories.
17
- - `infinite` adds `useInfiniteQuery` composables for pagination. It needs `hooks: true` and covers the operations that take the query parameter named in `infinite.queryParam`, which defaults to `'id'`.
18
- - `query` and `mutation` set which HTTP methods become queries (`GET`, `QUERY`) and mutations (`POST`, `PUT`, `PATCH`, `DELETE`). They also set where the TanStack Query runtime is imported from. Set either to `false` to skip those helpers.
19
-
20
- See [Options](https://kubb.dev/extensions/kubb-labs/plugin-vue-query/options) for every option and its default.
17
+ | Option | What it does |
18
+ | ------------------- | ------------------------------------------------------------------------------------------------ |
19
+ | `client` | Picks `'fetch'`, `'axios'`, or `'client'` when several client plugins are registered. |
20
+ | `hooks` | Adds the `use*` composables. `infinite` needs it. |
21
+ | `query`, `mutation` | Which HTTP methods become queries and mutations. `false` skips them. |
22
+ | `infinite` | Adds infinite queries to operations with the `infinite.queryParam` parameter, `'id'` by default. |
21
23
 
22
24
  ## Example
23
25
 
24
- The config below generates `useQuery` and `useMutation` composables that call the Fetch client.
26
+ This config generates composables that call the Fetch client.
25
27
 
26
28
  ```typescript [kubb.config.ts]
27
29
  import { defineConfig } from 'kubb/config'
@@ -41,3 +43,5 @@ export default defineConfig({
41
43
  ],
42
44
  })
43
45
  ```
46
+
47
+ See [Options](https://kubb.dev/extensions/kubb-labs/plugin-vue-query/options) for every option. Next, [call operations](https://kubb.dev/extensions/kubb-labs/plugin-vue-query/guides/calling-operations).
@@ -4,7 +4,7 @@
4
4
  "name": "plugin-vue-query",
5
5
  "export": "pluginVueQuery",
6
6
  "displayName": "Vue Query",
7
- "description": "Generates typed TanStack Query helpers for Vue from your OpenAPI spec: queryOptions factories with their query and mutation keys. Set hooks to also get useQuery and useMutation composables, plus useInfiniteQuery when infinite is set.",
7
+ "description": "Generates typed TanStack Query helpers for Vue from your OpenAPI spec: queryOptions factories with query and mutation keys, plus optional composables.",
8
8
  "category": "framework",
9
9
  "icon": {
10
10
  "light": "https://kubb.dev/feature/tanstack.svg"
@@ -19,7 +19,7 @@
19
19
  ],
20
20
  "optionalDependencies": ["plugin-ts", "plugin-zod"],
21
21
  "compatibility": {
22
- "kubb": ">=5.18.4",
22
+ "kubb": ">=5.19.0",
23
23
  "node": ">=22.22"
24
24
  },
25
25
  "role": "consumer",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-vue-query",
3
- "version": "5.10.3",
3
+ "version": "5.10.4",
4
4
  "description": "Generate type-safe TanStack Query (Vue Query) composables with Kubb. Covers useQuery, useMutation, useInfiniteQuery, and queryOptions with Vue 3 Composition API support.",
5
5
  "keywords": [
6
6
  "code-generation",
@@ -84,7 +84,7 @@
84
84
  },
85
85
  "dependencies": {
86
86
  "@kubb/kit": "^5.20.1",
87
- "@kubb/plugin-ts": "^5.5.3",
87
+ "@kubb/plugin-ts": "^5.5.4",
88
88
  "@kubb/renderer-jsx": "^5.20.1"
89
89
  },
90
90
  "devDependencies": {
@@ -92,7 +92,7 @@
92
92
  "@internals/shared": "0.0.0",
93
93
  "@internals/tanstack-query": "0.0.0",
94
94
  "@internals/utils": "0.0.0",
95
- "@kubb/plugin-client": "6.0.3",
95
+ "@kubb/plugin-client": "6.0.4",
96
96
  "@tanstack/vue-query": "^5.107.1",
97
97
  "vue": "^3.5.45"
98
98
  },