Skip to content

Commit d08100b

Browse files
authored
Merge pull request #2409 from hey-api/docs/tanstack-query-meta
docs: update TanStack Query meta docs
2 parents 036441a + ca4e1db commit d08100b

File tree

1 file changed

+77
-21
lines changed

1 file changed

+77
-21
lines changed

docs/openapi-ts/plugins/tanstack-query.md

Lines changed: 77 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,39 @@ export default {
133133

134134
You can customize the naming and casing pattern for `queryOptions` functions using the `.name` and `.case` options.
135135

136+
### Meta
137+
138+
You can use the `meta` field to attach arbitrary information to a query. To generate metadata for `queryOptions`, provide a function to the `.meta` option.
139+
140+
::: code-group
141+
142+
```ts [example]
143+
queryOptions({
144+
// ...other fields
145+
meta: {
146+
id: 'getPetById',
147+
},
148+
});
149+
```
150+
151+
```js [config]
152+
export default {
153+
input: 'https://get.heyapi.dev/hey-api/backend',
154+
output: 'src/client',
155+
plugins: [
156+
// ...other plugins
157+
{
158+
name: '@tanstack/react-query',
159+
queryOptions: {
160+
meta: (operation) => ({ id: operation.id }), // [!code ++]
161+
},
162+
},
163+
],
164+
};
165+
```
166+
167+
:::
168+
136169
## Query Keys
137170

138171
Query keys contain normalized SDK function parameters and additional metadata.
@@ -300,6 +333,39 @@ export default {
300333

301334
You can customize the naming and casing pattern for `infiniteQueryOptions` functions using the `.name` and `.case` options.
302335

336+
### Meta
337+
338+
You can use the `meta` field to attach arbitrary information to a query. To generate metadata for `infiniteQueryOptions`, provide a function to the `.meta` option.
339+
340+
::: code-group
341+
342+
```ts [example]
343+
infiniteQueryOptions({
344+
// ...other fields
345+
meta: {
346+
id: 'getPetById',
347+
},
348+
});
349+
```
350+
351+
```js [config]
352+
export default {
353+
input: 'https://get.heyapi.dev/hey-api/backend',
354+
output: 'src/client',
355+
plugins: [
356+
// ...other plugins
357+
{
358+
name: '@tanstack/react-query',
359+
infiniteQueryOptions: {
360+
meta: (operation) => ({ id: operation.id }), // [!code ++]
361+
},
362+
},
363+
],
364+
};
365+
```
366+
367+
:::
368+
303369
## Infinite Query Keys
304370

305371
Infinite query keys contain normalized SDK function parameters and additional metadata.
@@ -472,28 +538,18 @@ export default {
472538

473539
You can customize the naming and casing pattern for `mutationOptions` functions using the `.name` and `.case` options.
474540

475-
:::
476-
477-
## Meta Function Customization
541+
### Meta
478542

479-
The TanStack Query plugin supports custom meta functions that allow you to generate any metadata you want for your operations.
543+
You can use the `meta` field to attach arbitrary information to a mutation. To generate metadata for `mutationOptions`, provide a function to the `.meta` option.
480544

481545
::: code-group
482546

483547
```ts [example]
484-
export default {
485-
input: 'https://get.heyapi.dev/hey-api/backend',
486-
output: 'src/client',
487-
plugins: [
488-
{
489-
name: '@tanstack/react-query',
490-
queryOptions: {
491-
meta: (operation) => ({
492-
// ... your meta object
493-
}),
494-
},
495-
},
496-
],
548+
const mutationOptions = {
549+
// ...other fields
550+
meta: {
551+
id: 'getPetById',
552+
},
497553
};
498554
```
499555

@@ -505,16 +561,16 @@ export default {
505561
// ...other plugins
506562
{
507563
name: '@tanstack/react-query',
508-
queryOptions: {
509-
meta: (operation) => ({
510-
// ... your meta object
511-
}),
564+
mutationOptions: {
565+
meta: (operation) => ({ id: operation.id }), // [!code ++]
512566
},
513567
},
514568
],
515569
};
516570
```
517571

572+
:::
573+
518574
## API
519575

520576
You can view the complete list of options in the [UserConfig](https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/plugins/@tanstack/react-query/types.d.ts) interface.

0 commit comments

Comments
 (0)