@kubb/plugin-react-query 5.10.0 → 5.10.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.
@@ -12,16 +12,20 @@ A query hook takes the operation's grouped request config (`path`, `query`, `hea
12
12
  ```typescript
13
13
  import { useGetPetById } from './gen/hooks/useGetPetById'
14
14
 
15
- const { data, error, isLoading } = useGetPetById({ path: { petId: 1n } })
15
+ const { data, error, isLoading } = useGetPetById({ path: { petId: 1 } })
16
16
  ```
17
17
 
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`.
19
+
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.
21
+
18
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` or `signal`:
19
23
 
20
24
  ```typescript
21
25
  import { useGetPetById } from './gen/hooks/useGetPetById'
22
26
 
23
27
  useGetPetById(
24
- { path: { petId: 1n } },
28
+ { path: { petId: 1 } },
25
29
  {
26
30
  query: { staleTime: 60_000 },
27
31
  client: { baseURL: 'https://api.example.com/v1' },
@@ -39,8 +43,8 @@ import { getPetByIdQueryKey, getPetByIdQueryOptions } from './gen/hooks/useGetPe
39
43
 
40
44
  const queryClient = useQueryClient()
41
45
 
42
- await queryClient.prefetchQuery(getPetByIdQueryOptions({ path: { petId: 1n } }))
43
- queryClient.invalidateQueries({ queryKey: getPetByIdQueryKey({ path: { petId: 1n } }) })
46
+ await queryClient.prefetchQuery(getPetByIdQueryOptions({ path: { petId: 1 } }))
47
+ queryClient.invalidateQueries({ queryKey: getPetByIdQueryKey({ path: { petId: 1 } }) })
44
48
  ```
45
49
 
46
50
  ## Mutations
@@ -57,7 +61,7 @@ const { mutate } = useDeletePet({
57
61
  mutation: { onSuccess: () => queryClient.invalidateQueries() },
58
62
  })
59
63
 
60
- mutate({ path: { petId: 1n } })
64
+ mutate({ path: { petId: 1 } })
61
65
  ```
62
66
 
63
67
  Each mutation also exports a `mutationOptions` factory and a `mutationKey` helper.
@@ -111,7 +115,7 @@ const { data, fetchNextPage, hasNextPage } = useInfiniteQuery(
111
115
 
112
116
  ::
113
117
 
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.
118
+ `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.
115
119
 
116
120
  ## Use suspense
117
121
 
@@ -128,7 +132,7 @@ pluginReactQuery({ hooks: true, suspense: {} })
128
132
  ```typescript [usage.ts]
129
133
  import { useGetPetByIdSuspense } from './gen/hooks/useGetPetByIdSuspense'
130
134
 
131
- const { data } = useGetPetByIdSuspense({ path: { petId: 1n } })
135
+ const { data } = useGetPetByIdSuspense({ path: { petId: 1 } })
132
136
  ```
133
137
 
134
138
  ::
package/docs/options.md CHANGED
@@ -16,7 +16,7 @@ Pass these options to `pluginReactQuery()`. Shared options link to [Shared plugi
16
16
  | [`queryKey`](#querykey) | Build the `queryKey` for each query hook. | Exported `queryKeyTransformer` |
17
17
  | [`mutation`](#mutation) | Configure the mutation hooks. | `{ methods: ['POST', 'PUT', 'PATCH', 'DELETE'], importPath: '@tanstack/react-query' }` |
18
18
  | [`mutationKey`](#mutationkey) | Build the `mutationKey` for each mutation hook. | Exported `mutationKeyTransformer` |
19
- | [`customOptions`](#customoptions) | Route every hook through your own options function. | None |
19
+ | [`customOptions`](#customoptions) | Route every hook through a custom options function. | None |
20
20
  | [`hooks`](#hooks) | Emit `use*` hook functions on top of the factories. | `false` |
21
21
  | [`include`](https://kubb.dev/docs/5.x/reference/plugin-options#include) | Keep only operations that match. | None |
22
22
  | [`exclude`](https://kubb.dev/docs/5.x/reference/plugin-options#exclude) | Skip operations that match. | `[]` |
@@ -46,7 +46,7 @@ Calls the operations generated by [`@kubb/plugin-axios`](https://kubb.dev/extens
46
46
  :::
47
47
 
48
48
  :::field{name="'client'"}
49
- Calls the operations generated by [`@kubb/plugin-client`](https://kubb.dev/extensions/kubb-labs/plugin-client). Your client module must also export the `RequestConfig` and `ResponseErrorConfig` types.
49
+ 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.
50
50
  :::
51
51
 
52
52
  ::
@@ -64,7 +64,7 @@ Shape of the value the generated hooks resolve to.
64
64
  ::field-group
65
65
 
66
66
  :::field{name="'full'"}
67
- Returns the client's whole `RequestResult` (`{ status, data, error, contentType, headers, request, response }`), so a hook 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.
67
+ Returns the client's whole `RequestResult` (`{ status, data, error, contentType, headers, request, response }`), so a hook 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.
68
68
  :::
69
69
 
70
70
  :::field{name="'data'"}
@@ -82,6 +82,8 @@ const etag = result?.response.headers.get('ETag')
82
82
  const pet = result?.data
83
83
  ```
84
84
 
85
+ 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`.
86
+
85
87
  ### infinite
86
88
 
87
89
  Adds `infiniteQueryOptions` and `useInfiniteQuery` for operations that declare the query parameter named in `infinite.queryParam`. Needs [`hooks: true`](#hooks).
@@ -134,7 +136,7 @@ Path to the previous-page cursor on the response, in the same dot or array form.
134
136
 
135
137
  #### infinite.cursorParam
136
138
 
137
- Deprecated path to the cursor field, read for both `getNextPageParam` and `getPreviousPageParam` when set. Use `nextParam` and `previousParam` instead.
139
+ 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.
138
140
 
139
141
  | | |
140
142
  | -------- | ---------------- |
@@ -144,13 +146,13 @@ Deprecated path to the cursor field, read for both `getNextPageParam` and `getPr
144
146
 
145
147
  #### infinite.getNextPageParam
146
148
 
147
- Source code for TanStack Query's `getNextPageParam`, copied into the generated code as written. Use it when the next page must be computed instead of read from a field. Takes precedence over `nextParam` and `cursorParam`.
149
+ Source code for TanStack Query's `getNextPageParam`, copied into the generated code as written. 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`.
148
150
 
149
- | | |
150
- | -------- | ---------------- |
151
- | Type | `string \| null` |
152
- | Required | `false` |
153
- | Default | `null` |
151
+ | | |
152
+ | -------- | ------------------------------- |
153
+ | Type | `string \| PageParamFn \| null` |
154
+ | Required | `false` |
155
+ | Default | `null` |
154
156
 
155
157
  ```typescript
156
158
  infinite: {
@@ -160,17 +162,33 @@ infinite: {
160
162
  }
161
163
  ```
162
164
 
163
- Without `getNextPageParam`, `nextParam` or `cursorParam`, the hook 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.
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, pluginReactQuery } from '@kubb/plugin-react-query'
169
+
170
+ type PetsPage = { hasNext: boolean; number: number }
171
+
172
+ pluginReactQuery({
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 hook 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.
164
182
 
165
183
  #### infinite.getPreviousPageParam
166
184
 
167
- Source code for TanStack Query's `getPreviousPageParam`, copied into the generated code as written. Takes precedence over `previousParam` and `cursorParam`.
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`.
168
186
 
169
- | | |
170
- | -------- | ---------------- |
171
- | Type | `string \| null` |
172
- | Required | `false` |
173
- | Default | `null` |
187
+ | | |
188
+ | -------- | ------------------------------- |
189
+ | Type | `string \| PageParamFn \| null` |
190
+ | Required | `false` |
191
+ | Default | `null` |
174
192
 
175
193
  ### suspense
176
194
 
@@ -288,7 +306,7 @@ mutationKey: (props) => [JSON.stringify(props.node.operationId), ...mutationKeyT
288
306
 
289
307
  ### customOptions
290
308
 
291
- Routes every hook through your own function that returns extra options such as `onSuccess` or `select`. Also emits a `HookOptions` type that maps each hook name to its options type. Needs [`hooks: true`](#hooks).
309
+ Routes every hook through a custom function that returns extra options such as `onSuccess` or `select`. Also emits a `HookOptions` type that maps each hook name to its options type. Needs [`hooks: true`](#hooks).
292
310
 
293
311
  | | |
294
312
  | -------- | --------------------------------------- |
@@ -297,7 +315,7 @@ Routes every hook through your own function that returns extra options such as `
297
315
 
298
316
  #### customOptions.importPath
299
317
 
300
- Module of your custom-options hook, imported as a named import. It resolves from the generated hooks folder. When the module does not exist yet, Kubb writes a starter file there, but only when `importPath` stays inside the plugin's output folder. For a path outside it, create the module yourself.
318
+ Module of the custom-options hook, imported as a named import. The path resolves from the generated hooks folder. When the module does not exist yet, Kubb writes a starter file there, but only when `importPath` stays inside the plugin's output folder. The starter file imports `HookOptions` from the generated `HookOptions.ts` file. A module outside the output folder is never created.
301
319
 
302
320
  | | |
303
321
  | -------- | ---------------------------------- |
@@ -306,7 +324,7 @@ Module of your custom-options hook, imported as a named import. It resolves from
306
324
 
307
325
  #### customOptions.name
308
326
 
309
- Exported name of your custom-options hook.
327
+ Exported name of the custom-options hook.
310
328
 
311
329
  | | |
312
330
  | -------- | ------------------------ |
package/docs/overview.md CHANGED
@@ -12,12 +12,12 @@ The plugin ships no HTTP client. Each helper calls a function generated by a cli
12
12
 
13
13
  ## Options worth knowing
14
14
 
15
- - `client` picks `fetch` or `axios` when both client plugins are registered. A single client is detected automatically.
15
+ - `client` picks `fetch`, `axios`, or `client` when more than one client plugin is registered. A single client plugin is detected automatically.
16
16
  - `hooks` adds the `use*` hooks on top of the option factories.
17
17
  - `suspense: {}` adds `useSuspenseQuery` hooks. It needs `hooks: true`.
18
18
  - `infinite` adds `useInfiniteQuery` hooks for pagination. It needs `hooks: true` and covers the operations that take the query parameter named in `infinite.queryParam`, which defaults to `'id'`.
19
- - `query` and `mutation` set which HTTP methods become queries (`GET`) 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.
20
- - `customOptions: { importPath }` routes every hook through your own function that returns extra options. It needs `hooks: true`. Kubb creates a starter file at `importPath`, resolved from the generated hooks folder, when none exists and the path stays inside the plugin's output folder.
19
+ - `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.
20
+ - `customOptions: { importPath }` routes every hook through your own function that returns extra options. It needs `hooks: true`. `importPath` resolves from the generated hooks folder. Kubb creates a starter file there when none exists and the path stays inside the plugin's output folder.
21
21
 
22
22
  See [Options](https://kubb.dev/extensions/kubb-labs/plugin-react-query/options) for every option and its default.
23
23
 
@@ -27,6 +27,7 @@ The config below generates `useQuery` and `useMutation` hooks that call the Fetc
27
27
 
28
28
  ```typescript [kubb.config.ts]
29
29
  import { defineConfig } from 'kubb/config'
30
+ import { adapterOas } from '@kubb/adapter-oas'
30
31
  import { pluginTs } from '@kubb/plugin-ts'
31
32
  import { pluginFetch } from '@kubb/plugin-fetch'
32
33
  import { pluginReactQuery } from '@kubb/plugin-react-query'
@@ -34,6 +35,7 @@ import { pluginReactQuery } from '@kubb/plugin-react-query'
34
35
  export default defineConfig({
35
36
  input: './petStore.yaml',
36
37
  output: { path: './src/gen' },
38
+ adapter: adapterOas({ integerType: 'number' }),
37
39
  plugins: [
38
40
  pluginTs(),
39
41
  pluginFetch(),
@@ -17,8 +17,7 @@
17
17
  "github": "stijnvanhulle"
18
18
  }
19
19
  ],
20
- "dependencies": ["plugin-ts"],
21
- "optionalDependencies": ["plugin-zod"],
20
+ "optionalDependencies": ["plugin-ts", "plugin-zod"],
22
21
  "compatibility": {
23
22
  "kubb": ">=5.18.4",
24
23
  "node": ">=22.22"
@@ -97,7 +96,7 @@
97
96
  "key": "client",
98
97
  "path": ["client"],
99
98
  "label": "Client",
100
- "description": "HTTP client the generated hooks call. Only needed to disambiguate when both plugin-fetch and plugin-axios are enabled",
99
+ "description": "HTTP client the generated hooks call. Only needed to disambiguate when more than one of plugin-fetch, plugin-axios and plugin-client is enabled",
101
100
  "type": "select",
102
101
  "default": null,
103
102
  "choices": [
@@ -112,6 +111,10 @@
112
111
  {
113
112
  "label": "axios",
114
113
  "value": "axios"
114
+ },
115
+ {
116
+ "label": "client",
117
+ "value": "client"
115
118
  }
116
119
  ]
117
120
  },
@@ -192,9 +195,9 @@
192
195
  "key": "queryMethods",
193
196
  "path": ["query", "methods"],
194
197
  "label": "Query Methods",
195
- "description": "Comma-separated HTTP methods treated as queries (default: GET)",
198
+ "description": "Comma-separated HTTP methods treated as queries (default: GET, QUERY)",
196
199
  "type": "list",
197
- "default": ["GET"],
200
+ "default": ["GET", "QUERY"],
198
201
  "itemCase": "upper"
199
202
  },
200
203
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-react-query",
3
- "version": "5.10.0",
3
+ "version": "5.10.2",
4
4
  "description": "Generate type-safe TanStack Query (React Query) hooks with Kubb. Covers useQuery, useMutation, useInfiniteQuery, and queryOptions with full TypeScript support.",
5
5
  "keywords": [
6
6
  "code-generation",
@@ -81,17 +81,17 @@
81
81
  "registry": "https://registry.npmjs.org/"
82
82
  },
83
83
  "dependencies": {
84
- "@kubb/kit": "^5.18.6",
85
- "@kubb/plugin-ts": "^5.5.0",
86
- "@kubb/renderer-jsx": "^5.18.6"
84
+ "@kubb/kit": "^5.19.0",
85
+ "@kubb/plugin-ts": "^5.5.2",
86
+ "@kubb/renderer-jsx": "^5.19.0"
87
87
  },
88
88
  "devDependencies": {
89
89
  "@internals/client": "0.0.0",
90
90
  "@internals/shared": "0.0.0",
91
91
  "@internals/tanstack-query": "0.0.0",
92
92
  "@internals/utils": "0.0.0",
93
- "@kubb/plugin-client": "6.0.0",
94
- "@tanstack/react-query": "^5.106.1"
93
+ "@kubb/plugin-client": "6.0.2",
94
+ "@tanstack/react-query": "^5.107.1"
95
95
  },
96
96
  "peerDependencies": {
97
97
  "@tanstack/react-query": "^5.82.0"