@kubb/plugin-vue-query 5.10.3 → 5.10.5
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 +4 -0
- package/dist/index.cjs +26 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +26 -28
- package/dist/index.js.map +1 -1
- package/docs/guides/calling-operations.md +50 -77
- package/docs/guides/infinite-queries.md +88 -0
- package/docs/guides/query-keys.md +113 -0
- package/docs/options.md +163 -175
- package/docs/overview.md +16 -12
- package/kubb-extension.json +2 -2
- package/package.json +5 -5
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)
|
|
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
|
|
8
|
-
| ------------------------------------------------------------------------- |
|
|
9
|
-
| [`
|
|
10
|
-
| [`
|
|
11
|
-
| [`
|
|
12
|
-
| [`
|
|
13
|
-
| [`
|
|
14
|
-
| [`query`](#
|
|
15
|
-
| [`queryKey`](#querykey) | Build the `queryKey`
|
|
16
|
-
| [`mutation`](#mutation) |
|
|
17
|
-
| [`
|
|
18
|
-
| [`
|
|
19
|
-
| [`
|
|
20
|
-
| [`
|
|
21
|
-
| [`
|
|
22
|
-
| [`
|
|
23
|
-
| [`
|
|
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
|
-
|
|
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
|
|
50
|
+
Calls [`@kubb/plugin-fetch`](https://kubb.dev/extensions/kubb-labs/plugin-fetch).
|
|
40
51
|
:::
|
|
41
52
|
|
|
42
53
|
:::field{name="'axios'"}
|
|
43
|
-
Calls
|
|
54
|
+
Calls [`@kubb/plugin-axios`](https://kubb.dev/extensions/kubb-labs/plugin-axios).
|
|
44
55
|
:::
|
|
45
56
|
|
|
46
57
|
:::field{name="'client'"}
|
|
47
|
-
Calls
|
|
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
|
-
|
|
65
|
+
What the composables resolve to.
|
|
55
66
|
|
|
56
67
|
| | |
|
|
57
68
|
| -------- | ------------------ |
|
|
58
|
-
| Type | `'
|
|
69
|
+
| Type | `'data' \| 'full'` |
|
|
59
70
|
| Required | `false` |
|
|
60
71
|
| Default | `'data'` |
|
|
61
72
|
|
|
62
73
|
::field-group
|
|
63
74
|
|
|
64
|
-
:::field{name="'
|
|
65
|
-
|
|
75
|
+
:::field{name="'data'"}
|
|
76
|
+
Resolves to the success body.
|
|
66
77
|
:::
|
|
67
78
|
|
|
68
|
-
:::field{name="'
|
|
69
|
-
|
|
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
|
-
```
|
|
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
|
-
|
|
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
|
-
|
|
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 | `
|
|
99
|
+
| Type | `boolean` |
|
|
122
100
|
| Required | `false` |
|
|
123
|
-
| Default | `
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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 |
|
|
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
|
-
|
|
242
|
-
|
|
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
|
|
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(
|
|
151
|
+
queryKey: (props) => [JSON.stringify('v2'), ...queryKeyTransformer(props)]
|
|
253
152
|
```
|
|
254
153
|
|
|
255
154
|
### mutation
|
|
256
155
|
|
|
257
|
-
|
|
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
|
|
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
|
|
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
|
|
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 |
|
|
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(
|
|
197
|
+
mutationKey: (props) => [JSON.stringify('v2'), ...mutationKeyTransformer(props)]
|
|
301
198
|
```
|
|
302
199
|
|
|
303
|
-
###
|
|
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
|
-
|
|
225
|
+
`pageParam` of the first fetch. Give it the type of the query parameter.
|
|
306
226
|
|
|
307
227
|
| | |
|
|
308
228
|
| -------- | --------- |
|
|
309
|
-
| Type | `
|
|
229
|
+
| Type | `unknown` |
|
|
310
230
|
| Required | `false` |
|
|
311
|
-
| Default | `
|
|
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
|
|
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
|
-
|
|
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
|
|
3
|
+
The Vue Query plugin generates TanStack Query `queryOptions` factories, query and mutation keys, and optional composables from your OpenAPI spec.
|
|
4
4
|
|
|
5
|
-
|
|
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' })`
|
|
10
|
-
-
|
|
11
|
-
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
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).
|
package/kubb-extension.json
CHANGED
|
@@ -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
|
|
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.
|
|
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
|
+
"version": "5.10.5",
|
|
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",
|
|
@@ -83,16 +83,16 @@
|
|
|
83
83
|
"registry": "https://registry.npmjs.org/"
|
|
84
84
|
},
|
|
85
85
|
"dependencies": {
|
|
86
|
-
"@kubb/kit": "^5.
|
|
87
|
-
"@kubb/plugin-ts": "^5.5.
|
|
88
|
-
"@kubb/renderer-jsx": "^5.
|
|
86
|
+
"@kubb/kit": "^5.21.1",
|
|
87
|
+
"@kubb/plugin-ts": "^5.5.5",
|
|
88
|
+
"@kubb/renderer-jsx": "^5.21.1"
|
|
89
89
|
},
|
|
90
90
|
"devDependencies": {
|
|
91
91
|
"@internals/client": "0.0.0",
|
|
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.
|
|
95
|
+
"@kubb/plugin-client": "6.1.1",
|
|
96
96
|
"@tanstack/vue-query": "^5.107.1",
|
|
97
97
|
"vue": "^3.5.45"
|
|
98
98
|
},
|