@kubb/plugin-vue-query 5.3.1 → 5.3.2
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/README.md +2 -2
- package/dist/index.cjs +4 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +5 -4
- package/dist/index.js.map +1 -1
- package/docs/guides/calling-operations.md +132 -0
- package/docs/options.md +271 -0
- package/{OVERVIEW.md → docs/overview.md} +23 -0
- package/kubb-extension.json +9 -2
- package/package.json +6 -6
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# Call operations
|
|
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` or `@kubb/plugin-axios`.
|
|
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.
|
|
7
|
+
|
|
8
|
+
## Queries
|
|
9
|
+
|
|
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).
|
|
11
|
+
|
|
12
|
+
```typescript [usage.ts]
|
|
13
|
+
import { useGetPetById } from './gen/hooks/useGetPetById'
|
|
14
|
+
|
|
15
|
+
const { data, error, isLoading } = useGetPetById({ path: { petId: 1n } })
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
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`:
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
import { useFindPetsByTags } from './gen/hooks/useFindPetsByTags'
|
|
22
|
+
|
|
23
|
+
useFindPetsByTags(
|
|
24
|
+
{ query: { tags: ['dog'] } },
|
|
25
|
+
{
|
|
26
|
+
query: { staleTime: 60_000 },
|
|
27
|
+
client: { baseURL: 'https://api.example.com/v1' },
|
|
28
|
+
},
|
|
29
|
+
)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Factories
|
|
33
|
+
|
|
34
|
+
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:
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import { useQueryClient } from '@tanstack/vue-query'
|
|
38
|
+
import { findPetsByTagsQueryKey, findPetsByTagsQueryOptions } from './gen/hooks/useFindPetsByTags'
|
|
39
|
+
|
|
40
|
+
const queryClient = useQueryClient()
|
|
41
|
+
|
|
42
|
+
await queryClient.prefetchQuery(findPetsByTagsQueryOptions({ query: { tags: ['dog'] } }))
|
|
43
|
+
queryClient.invalidateQueries({ queryKey: findPetsByTagsQueryKey({ query: { tags: ['dog'] } }) })
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Mutations export a `mutationKey` helper next to the composable.
|
|
47
|
+
|
|
48
|
+
## Mutations
|
|
49
|
+
|
|
50
|
+
A mutation composable takes only an options object. The grouped request config is the mutation variable, so you pass it to `mutate` or `mutateAsync`:
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import { useQueryClient } from '@tanstack/vue-query'
|
|
54
|
+
import { useUpdatePetWithForm } from './gen/hooks/useUpdatePetWithForm'
|
|
55
|
+
|
|
56
|
+
const queryClient = useQueryClient()
|
|
57
|
+
|
|
58
|
+
const { mutate } = useUpdatePetWithForm({
|
|
59
|
+
mutation: { onSuccess: () => queryClient.invalidateQueries() },
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
mutate({ path: { petId: 1n }, query: { name: 'Fluffy' } })
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Errors and transport
|
|
66
|
+
|
|
67
|
+
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.
|
|
68
|
+
|
|
69
|
+
## Customize cache keys
|
|
70
|
+
|
|
71
|
+
Set `queryKey` on the plugin to change generated keys. String entries are emitted as source code, so use `JSON.stringify` for a string literal.
|
|
72
|
+
|
|
73
|
+
```typescript [kubb.config.ts]
|
|
74
|
+
import { pluginVueQuery } from '@kubb/plugin-vue-query'
|
|
75
|
+
|
|
76
|
+
pluginVueQuery({
|
|
77
|
+
queryKey: ({ node }) => [JSON.stringify(node.operationId)],
|
|
78
|
+
})
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
> [!WARNING]
|
|
82
|
+
> This `queryKey` gives every call the same key, such as `['getUserByName']`. If path or query values select different data, add them to the key.
|
|
83
|
+
|
|
84
|
+
## Load more pages
|
|
85
|
+
|
|
86
|
+
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.
|
|
87
|
+
|
|
88
|
+
::code-group
|
|
89
|
+
|
|
90
|
+
```typescript [kubb.config.ts]
|
|
91
|
+
import { pluginVueQuery } from '@kubb/plugin-vue-query'
|
|
92
|
+
|
|
93
|
+
pluginVueQuery({
|
|
94
|
+
hooks: true,
|
|
95
|
+
infinite: {
|
|
96
|
+
queryParam: 'page',
|
|
97
|
+
initialPageParam: 0,
|
|
98
|
+
nextParam: 'pagination.next.cursor',
|
|
99
|
+
},
|
|
100
|
+
})
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
```typescript [usage.ts]
|
|
104
|
+
import { useInfiniteQuery } from '@tanstack/vue-query'
|
|
105
|
+
import { findPetsByTagsInfiniteQueryOptions } from './gen/hooks/useFindPetsByTagsInfinite'
|
|
106
|
+
|
|
107
|
+
const { data, fetchNextPage, hasNextPage } = useInfiniteQuery(
|
|
108
|
+
findPetsByTagsInfiniteQueryOptions({ query: () => ({ tags: ['dog'] }) }),
|
|
109
|
+
)
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
::
|
|
113
|
+
|
|
114
|
+
`nextParam` takes dot notation or an array of keys. Change it to match your API's response. Without `getNextPageParam`, `nextParam` or `cursorParam`, the generated options increment the page number until a page returns an empty array.
|
|
115
|
+
|
|
116
|
+
## Refetch when parameters change
|
|
117
|
+
|
|
118
|
+
Enable `hooks: true`, then pass a ref or getter to a generated composable. Parameters accept `MaybeRefOrGetter`. A getter tracks its reactive dependencies.
|
|
119
|
+
|
|
120
|
+
```typescript [usage.ts]
|
|
121
|
+
import { ref } from 'vue'
|
|
122
|
+
import { useFindPetsByTags } from './gen/hooks/useFindPetsByTags'
|
|
123
|
+
|
|
124
|
+
const tags = ref(['dog'])
|
|
125
|
+
const { data, error, isLoading } = useFindPetsByTags({
|
|
126
|
+
query: () => ({ tags: tags.value }),
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
tags.value = ['cat']
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Changing `tags.value` updates the query key and fetches the corresponding resource.
|
package/docs/options.md
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
# Options
|
|
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.
|
|
4
|
+
|
|
5
|
+
## Options overview
|
|
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
|
+
| [`infinite`](#infinite) | Add `useInfiniteQuery` composables for paginated reads. | `false` |
|
|
13
|
+
| [`query`](#query) | Configure or disable query composables. | `{ methods: ['GET'], importPath: '@tanstack/vue-query' }` |
|
|
14
|
+
| [`queryKey`](#querykey) | Build the `queryKey` for each query composable. | Built-in `queryKeyTransformer` |
|
|
15
|
+
| [`mutation`](#mutation) | Configure or disable mutation composables. | `{ methods: ['POST', 'PUT', 'PATCH', 'DELETE'], importPath: '@tanstack/vue-query' }` |
|
|
16
|
+
| [`mutationKey`](#mutationkey) | Build the `mutationKey` for each mutation composable. | Built-in `mutationKeyTransformer` |
|
|
17
|
+
| [`hooks`](#hooks) | Emit `use*` composables on top of the factory helpers. | `false` |
|
|
18
|
+
| [`include`](https://kubb.dev/docs/5.x/reference/plugin-options#include) | Keep only operations that match. | None |
|
|
19
|
+
| [`exclude`](https://kubb.dev/docs/5.x/reference/plugin-options#exclude) | Skip operations that match. | `[]` |
|
|
20
|
+
| [`override`](https://kubb.dev/docs/5.x/reference/plugin-options#override) | Apply different options per pattern. | `[]` |
|
|
21
|
+
| [`resolver`](#resolver) | Customize generated names and file paths. | `resolverVueQuery` |
|
|
22
|
+
| [`macros`](https://kubb.dev/docs/5.x/reference/plugin-options#macros) | Rewrite AST nodes before printing. | `[]` |
|
|
23
|
+
|
|
24
|
+
## Option details
|
|
25
|
+
|
|
26
|
+
### client
|
|
27
|
+
|
|
28
|
+
Selects which registered client plugin the composables call. A single registered client is auto-detected. Set `client` when several are registered.
|
|
29
|
+
|
|
30
|
+
| | |
|
|
31
|
+
| -------- | -------------------- |
|
|
32
|
+
| Type | `'axios' \| 'fetch'` |
|
|
33
|
+
| Required | `false` |
|
|
34
|
+
|
|
35
|
+
::field-group
|
|
36
|
+
|
|
37
|
+
:::field{name="'fetch'"}
|
|
38
|
+
Calls the operations generated by [`@kubb/plugin-fetch`](https://kubb.dev/extensions/kubb-labs/plugin-fetch).
|
|
39
|
+
:::
|
|
40
|
+
|
|
41
|
+
:::field{name="'axios'"}
|
|
42
|
+
Calls the operations generated by [`@kubb/plugin-axios`](https://kubb.dev/extensions/kubb-labs/plugin-axios).
|
|
43
|
+
:::
|
|
44
|
+
|
|
45
|
+
::
|
|
46
|
+
|
|
47
|
+
### infinite
|
|
48
|
+
|
|
49
|
+
Adds `infiniteQueryOptions` and `useInfiniteQuery` for operations that declare the query parameter named in `infinite.queryParam`. Needs [`hooks: true`](#hooks).
|
|
50
|
+
|
|
51
|
+
| | |
|
|
52
|
+
| -------- | ---------------------------- |
|
|
53
|
+
| Type | `Partial<Infinite> \| false` |
|
|
54
|
+
| Required | `false` |
|
|
55
|
+
| Default | `false` |
|
|
56
|
+
|
|
57
|
+
```typescript [infinite: {}, hooks: true]
|
|
58
|
+
export function getPetsInfiniteQueryOptions(/* ... */) {
|
|
59
|
+
return infiniteQueryOptions({ queryKey, queryFn, initialPageParam, getNextPageParam })
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function useGetPetsInfiniteQuery(/* ... */) {
|
|
63
|
+
return useInfiniteQuery(getPetsInfiniteQueryOptions(/* ... */))
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
#### infinite.queryParam
|
|
68
|
+
|
|
69
|
+
Name of the query parameter that holds the page cursor.
|
|
70
|
+
|
|
71
|
+
| | |
|
|
72
|
+
| -------- | -------- |
|
|
73
|
+
| Type | `string` |
|
|
74
|
+
| Required | `false` |
|
|
75
|
+
| Default | `'id'` |
|
|
76
|
+
|
|
77
|
+
#### infinite.initialPageParam
|
|
78
|
+
|
|
79
|
+
Initial value for `pageParam` on the first fetch.
|
|
80
|
+
|
|
81
|
+
| | |
|
|
82
|
+
| -------- | --------- |
|
|
83
|
+
| Type | `unknown` |
|
|
84
|
+
| Required | `false` |
|
|
85
|
+
| Default | `0` |
|
|
86
|
+
|
|
87
|
+
#### infinite.nextParam
|
|
88
|
+
|
|
89
|
+
Path to the next-page cursor on the response, as dot notation (`'pagination.next.id'`) or array form (`['pagination', 'next', 'id']`).
|
|
90
|
+
|
|
91
|
+
| | |
|
|
92
|
+
| -------- | --------------------------------- |
|
|
93
|
+
| Type | `string \| Array<string> \| null` |
|
|
94
|
+
| Required | `false` |
|
|
95
|
+
| Default | `null` |
|
|
96
|
+
|
|
97
|
+
#### infinite.previousParam
|
|
98
|
+
|
|
99
|
+
Path to the previous-page cursor on the response, in the same dot or array form.
|
|
100
|
+
|
|
101
|
+
| | |
|
|
102
|
+
| -------- | --------------------------------- |
|
|
103
|
+
| Type | `string \| Array<string> \| null` |
|
|
104
|
+
| Required | `false` |
|
|
105
|
+
| Default | `null` |
|
|
106
|
+
|
|
107
|
+
#### infinite.cursorParam
|
|
108
|
+
|
|
109
|
+
Deprecated path to the cursor field, read for both `getNextPageParam` and `getPreviousPageParam` when set. Use `nextParam` and `previousParam` instead.
|
|
110
|
+
|
|
111
|
+
| | |
|
|
112
|
+
| -------- | ---------------- |
|
|
113
|
+
| Type | `string \| null` |
|
|
114
|
+
| Required | `false` |
|
|
115
|
+
| Default | `null` |
|
|
116
|
+
|
|
117
|
+
#### infinite.getNextPageParam
|
|
118
|
+
|
|
119
|
+
Source code for TanStack Query's `getNextPageParam`, copied into the generated code as written, such as `'(lastPage) => (lastPage.hasNext ? lastPage.number + 1 : undefined)'`. Use it when the next page must be computed instead of read from a field. Takes precedence over `nextParam` and `cursorParam`.
|
|
120
|
+
|
|
121
|
+
| | |
|
|
122
|
+
| -------- | ---------------- |
|
|
123
|
+
| Type | `string \| null` |
|
|
124
|
+
| Required | `false` |
|
|
125
|
+
| Default | `null` |
|
|
126
|
+
|
|
127
|
+
Without `getNextPageParam`, `nextParam` or `cursorParam`, the composable counts pages up from `initialPageParam` until a page is an empty array. This works only for array responses, so generation warns when the response is an object.
|
|
128
|
+
|
|
129
|
+
#### infinite.getPreviousPageParam
|
|
130
|
+
|
|
131
|
+
Source code for TanStack Query's `getPreviousPageParam`, copied into the generated code as written. Takes precedence over `previousParam` and `cursorParam`.
|
|
132
|
+
|
|
133
|
+
| | |
|
|
134
|
+
| -------- | ---------------- |
|
|
135
|
+
| Type | `string \| null` |
|
|
136
|
+
| Required | `false` |
|
|
137
|
+
| Default | `null` |
|
|
138
|
+
|
|
139
|
+
### query
|
|
140
|
+
|
|
141
|
+
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`.
|
|
142
|
+
|
|
143
|
+
| | |
|
|
144
|
+
| -------- | --------------------------------------------------------- |
|
|
145
|
+
| Type | `Partial<Query> \| false` |
|
|
146
|
+
| Required | `false` |
|
|
147
|
+
| Default | `{ methods: ['GET'], importPath: '@tanstack/vue-query' }` |
|
|
148
|
+
|
|
149
|
+
#### query.methods
|
|
150
|
+
|
|
151
|
+
HTTP methods treated as queries. A matching operation generates a `queryOptions` factory instead of a mutation.
|
|
152
|
+
|
|
153
|
+
| | |
|
|
154
|
+
| -------- | --------------- |
|
|
155
|
+
| Type | `Array<string>` |
|
|
156
|
+
| Required | `false` |
|
|
157
|
+
| Default | `['GET']` |
|
|
158
|
+
|
|
159
|
+
#### query.importPath
|
|
160
|
+
|
|
161
|
+
Module specifier for the generated `import { queryOptions } from '...'`.
|
|
162
|
+
|
|
163
|
+
| | |
|
|
164
|
+
| -------- | ----------------------- |
|
|
165
|
+
| Type | `string` |
|
|
166
|
+
| Required | `false` |
|
|
167
|
+
| Default | `'@tanstack/vue-query'` |
|
|
168
|
+
|
|
169
|
+
### queryKey
|
|
170
|
+
|
|
171
|
+
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.
|
|
172
|
+
|
|
173
|
+
| | |
|
|
174
|
+
| -------- | ------------------------------------------------------ |
|
|
175
|
+
| Type | `(props: { node, casing, variant }) => Array<unknown>` |
|
|
176
|
+
| Required | `false` |
|
|
177
|
+
| Default | Built-in `queryKeyTransformer` |
|
|
178
|
+
|
|
179
|
+
::code-group
|
|
180
|
+
|
|
181
|
+
```typescript [queryKey builder]
|
|
182
|
+
queryKey: ({ node, variant }) => [JSON.stringify({ variant, operationId: node.operationId })]
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
```typescript [Generated output]
|
|
186
|
+
export const getUserByNameQueryKey = () => [{ variant: 'query', operationId: 'getUserByName' }] as const
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
::
|
|
190
|
+
|
|
191
|
+
### mutation
|
|
192
|
+
|
|
193
|
+
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`.
|
|
194
|
+
|
|
195
|
+
| | |
|
|
196
|
+
| -------- | ------------------------------------------------------------------------------------ |
|
|
197
|
+
| Type | `Partial<Mutation> \| false` |
|
|
198
|
+
| Required | `false` |
|
|
199
|
+
| Default | `{ methods: ['POST', 'PUT', 'PATCH', 'DELETE'], importPath: '@tanstack/vue-query' }` |
|
|
200
|
+
|
|
201
|
+
#### mutation.methods
|
|
202
|
+
|
|
203
|
+
HTTP methods treated as mutations. A matching operation generates mutation output instead of a query.
|
|
204
|
+
|
|
205
|
+
| | |
|
|
206
|
+
| -------- | ------------------------------------ |
|
|
207
|
+
| Type | `Array<string>` |
|
|
208
|
+
| Required | `false` |
|
|
209
|
+
| Default | `['POST', 'PUT', 'PATCH', 'DELETE']` |
|
|
210
|
+
|
|
211
|
+
#### mutation.importPath
|
|
212
|
+
|
|
213
|
+
Module specifier for the generated `import { useMutation } from '...'`, emitted when [`hooks`](#hooks) is set.
|
|
214
|
+
|
|
215
|
+
| | |
|
|
216
|
+
| -------- | ----------------------- |
|
|
217
|
+
| Type | `string` |
|
|
218
|
+
| Required | `false` |
|
|
219
|
+
| Default | `'@tanstack/vue-query'` |
|
|
220
|
+
|
|
221
|
+
### mutationKey
|
|
222
|
+
|
|
223
|
+
Builds the `mutationKey` for each mutation composable, useful for batching invalidations. It takes the same props as `queryKey` with `variant: 'mutation'` and inlines strings the same way, so wrap literals in `JSON.stringify(...)`.
|
|
224
|
+
|
|
225
|
+
| | |
|
|
226
|
+
| -------- | ------------------------------------------------------ |
|
|
227
|
+
| Type | `(props: { node, casing, variant }) => Array<unknown>` |
|
|
228
|
+
| Required | `false` |
|
|
229
|
+
| Default | Built-in `mutationKeyTransformer` |
|
|
230
|
+
|
|
231
|
+
### hooks
|
|
232
|
+
|
|
233
|
+
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`.
|
|
234
|
+
|
|
235
|
+
| | |
|
|
236
|
+
| -------- | --------- |
|
|
237
|
+
| Type | `boolean` |
|
|
238
|
+
| Required | `false` |
|
|
239
|
+
| Default | `false` |
|
|
240
|
+
|
|
241
|
+
### resolver
|
|
242
|
+
|
|
243
|
+
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).
|
|
244
|
+
|
|
245
|
+
| | |
|
|
246
|
+
| -------- | --------------------------------- |
|
|
247
|
+
| Type | `ResolverPatch<ResolverVueQuery>` |
|
|
248
|
+
| Required | `false` |
|
|
249
|
+
|
|
250
|
+
::code-collapse{name="ResolverVueQuery patch members"}
|
|
251
|
+
|
|
252
|
+
```typescript [Partial override]
|
|
253
|
+
type ResolverVueQueryPatch = {
|
|
254
|
+
// plus the shared name, file, and imports members
|
|
255
|
+
query?: {
|
|
256
|
+
name?(node: OperationNode): string
|
|
257
|
+
optionsName?(node: OperationNode): string
|
|
258
|
+
keyName?(node: OperationNode): string
|
|
259
|
+
keyTypeName?(node: OperationNode): string
|
|
260
|
+
clientName?(node: OperationNode): string
|
|
261
|
+
}
|
|
262
|
+
infiniteQuery?: { /* same members as query */ }
|
|
263
|
+
mutation?: {
|
|
264
|
+
name?(node: OperationNode): string
|
|
265
|
+
keyName?(node: OperationNode): string
|
|
266
|
+
typeName?(node: OperationNode): string
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
::
|
|
@@ -16,3 +16,26 @@ The plugin ships no HTTP client. Each helper calls a function generated by a cli
|
|
|
16
16
|
- `hooks` adds the `use*` composables on top of the option factories.
|
|
17
17
|
- `infinite` adds infinite queries for pagination. Set `infinite.queryParam` to the query parameter that holds the page cursor.
|
|
18
18
|
- `query` and `mutation` set which HTTP methods become queries (`GET`) and mutations (`POST`, `PUT`, `PATCH`, `DELETE`), and where the TanStack Query runtime is imported from. Set either to `false` to skip it.
|
|
19
|
+
|
|
20
|
+
## Example
|
|
21
|
+
|
|
22
|
+
```typescript [kubb.config.ts]
|
|
23
|
+
import { defineConfig } from 'kubb/config'
|
|
24
|
+
import { pluginTs } from '@kubb/plugin-ts'
|
|
25
|
+
import { pluginFetch } from '@kubb/plugin-fetch'
|
|
26
|
+
import { pluginVueQuery } from '@kubb/plugin-vue-query'
|
|
27
|
+
|
|
28
|
+
export default defineConfig({
|
|
29
|
+
input: './petStore.yaml',
|
|
30
|
+
output: { path: './src/gen' },
|
|
31
|
+
plugins: [
|
|
32
|
+
pluginTs(),
|
|
33
|
+
pluginFetch(),
|
|
34
|
+
pluginVueQuery({ hooks: true }),
|
|
35
|
+
],
|
|
36
|
+
})
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## See also
|
|
40
|
+
|
|
41
|
+
- [TanStack Query for Vue](https://tanstack.com/query/latest/docs/framework/vue/overview)
|
package/kubb-extension.json
CHANGED
|
@@ -10,9 +10,16 @@
|
|
|
10
10
|
"light": "https://kubb.dev/feature/tanstack.svg"
|
|
11
11
|
},
|
|
12
12
|
"tags": ["vue-query", "tanstack-query", "vue", "composables", "data-fetching", "codegen", "openapi"],
|
|
13
|
-
"docs": "https://kubb.dev/
|
|
13
|
+
"docs": "https://kubb.dev/extensions/kubb-labs/plugin-vue-query",
|
|
14
|
+
"maintainers": [
|
|
15
|
+
{
|
|
16
|
+
"name": "Stijn Van Hulle",
|
|
17
|
+
"github": "stijnvanhulle"
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
"dependencies": ["plugin-ts"],
|
|
14
21
|
"compatibility": {
|
|
15
|
-
"kubb": ">=5.8.
|
|
22
|
+
"kubb": ">=5.8.3",
|
|
16
23
|
"node": ">=22"
|
|
17
24
|
},
|
|
18
25
|
"role": "consumer",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-vue-query",
|
|
3
|
-
"version": "5.3.
|
|
3
|
+
"version": "5.3.2",
|
|
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",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"vue-query",
|
|
20
20
|
"vue3"
|
|
21
21
|
],
|
|
22
|
-
"homepage": "https://kubb.dev/
|
|
22
|
+
"homepage": "https://kubb.dev/extensions/kubb-labs/plugin-vue-query",
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"author": "stijnvanhulle",
|
|
25
25
|
"repository": {
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"files": [
|
|
45
45
|
"dist",
|
|
46
46
|
"kubb-extension.json",
|
|
47
|
-
"
|
|
47
|
+
"docs",
|
|
48
48
|
"!/**/**.test.**",
|
|
49
49
|
"!/**/__tests__/**",
|
|
50
50
|
"!/**/__snapshots__/**"
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"registry": "https://registry.npmjs.org/"
|
|
79
79
|
},
|
|
80
80
|
"dependencies": {
|
|
81
|
-
"@kubb/plugin-ts": "^5.0.
|
|
81
|
+
"@kubb/plugin-ts": "^5.0.9"
|
|
82
82
|
},
|
|
83
83
|
"devDependencies": {
|
|
84
84
|
"@internals/client": "0.0.0",
|
|
@@ -86,11 +86,11 @@
|
|
|
86
86
|
"@internals/tanstack-query": "0.0.0",
|
|
87
87
|
"@internals/utils": "0.0.0",
|
|
88
88
|
"@tanstack/vue-query": "^5.104.1",
|
|
89
|
-
"kubb": "^5.8.
|
|
89
|
+
"kubb": "^5.8.3"
|
|
90
90
|
},
|
|
91
91
|
"peerDependencies": {
|
|
92
92
|
"@tanstack/vue-query": "^5.0.0",
|
|
93
|
-
"kubb": "^5.8.
|
|
93
|
+
"kubb": "^5.8.3"
|
|
94
94
|
},
|
|
95
95
|
"peerDependenciesMeta": {
|
|
96
96
|
"@tanstack/vue-query": {
|