@kubb/plugin-react-query 3.0.0-alpha.14 → 3.0.0-alpha.16

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.
Files changed (73) hide show
  1. package/dist/chunk-ESENIDWJ.js +608 -0
  2. package/dist/chunk-ESENIDWJ.js.map +1 -0
  3. package/dist/chunk-JQEH3UHY.cjs +618 -0
  4. package/dist/chunk-JQEH3UHY.cjs.map +1 -0
  5. package/dist/chunk-KRG2LWHM.cjs +606 -0
  6. package/dist/chunk-KRG2LWHM.cjs.map +1 -0
  7. package/dist/chunk-ME7ZFS5H.js +596 -0
  8. package/dist/chunk-ME7ZFS5H.js.map +1 -0
  9. package/dist/components.cjs +17 -5
  10. package/dist/components.d.cts +143 -5
  11. package/dist/components.d.ts +143 -5
  12. package/dist/components.js +1 -1
  13. package/dist/generators.cjs +25 -0
  14. package/dist/generators.cjs.map +1 -0
  15. package/dist/generators.d.cts +15 -0
  16. package/dist/generators.d.ts +15 -0
  17. package/dist/generators.js +4 -0
  18. package/dist/generators.js.map +1 -0
  19. package/dist/index.cjs +33 -76
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.cts +2 -4
  22. package/dist/index.d.ts +2 -4
  23. package/dist/index.js +34 -77
  24. package/dist/index.js.map +1 -1
  25. package/dist/types-DJxL-JeY.d.cts +195 -0
  26. package/dist/types-DJxL-JeY.d.ts +195 -0
  27. package/package.json +23 -15
  28. package/src/components/InfiniteQuery.tsx +129 -0
  29. package/src/components/InfiniteQueryOptions.tsx +121 -0
  30. package/src/components/Mutation.tsx +112 -304
  31. package/src/components/Query.tsx +91 -593
  32. package/src/components/QueryKey.tsx +51 -182
  33. package/src/components/QueryOptions.tsx +64 -465
  34. package/src/components/SuspenseQuery.tsx +129 -0
  35. package/src/components/index.ts +3 -0
  36. package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +64 -0
  37. package/src/generators/__snapshots__/clientGetImportPath.ts +64 -0
  38. package/src/generators/__snapshots__/clientPostImportPath.ts +59 -0
  39. package/src/generators/__snapshots__/findByTags.ts +64 -0
  40. package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +64 -0
  41. package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +64 -0
  42. package/src/generators/__snapshots__/findByTagsWithZod.ts +64 -0
  43. package/src/generators/__snapshots__/findInfiniteByTags.ts +74 -0
  44. package/src/generators/__snapshots__/findInfiniteByTagsCursor.ts +74 -0
  45. package/src/generators/__snapshots__/getAsMutation.ts +31 -0
  46. package/src/generators/__snapshots__/postAsQuery.ts +77 -0
  47. package/src/generators/__snapshots__/updatePetById.ts +59 -0
  48. package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +63 -0
  49. package/src/generators/index.ts +4 -0
  50. package/src/generators/infiniteQueryGenerator.tsx +124 -0
  51. package/src/generators/mutationGenerator.tsx +94 -0
  52. package/src/generators/queryGenerator.tsx +121 -0
  53. package/src/generators/suspenseQueryGenerator.tsx +120 -0
  54. package/src/plugin.ts +38 -49
  55. package/src/types.ts +35 -59
  56. package/dist/chunk-AGLJPONA.cjs +0 -1423
  57. package/dist/chunk-AGLJPONA.cjs.map +0 -1
  58. package/dist/chunk-I7X4HNDR.js +0 -1413
  59. package/dist/chunk-I7X4HNDR.js.map +0 -1
  60. package/dist/index-BzoLlZve.d.cts +0 -537
  61. package/dist/index-BzoLlZve.d.ts +0 -537
  62. package/src/OperationGenerator.tsx +0 -57
  63. package/src/__snapshots__/mutateAsQuery/updatePetWithForm.ts +0 -69
  64. package/src/__snapshots__/pathParamsTypeInline/getPetById.ts +0 -62
  65. package/src/__snapshots__/pathParamsTypeObject/getPetById.ts +0 -68
  66. package/src/__snapshots__/queryOptions/getPetById.ts +0 -41
  67. package/src/__snapshots__/queryWithoutQueryOptions/getPetById.ts +0 -51
  68. package/src/__snapshots__/variablesTypeMutate/deletePet.ts +0 -24
  69. package/src/components/QueryImports.tsx +0 -167
  70. package/src/components/SchemaType.tsx +0 -74
  71. package/src/components/__snapshots__/gen/showPetById.ts +0 -67
  72. package/src/components/__snapshots__/gen/useCreatePets.ts +0 -46
  73. package/src/components/__snapshots__/gen/useCreatePetsMutate.ts +0 -46
@@ -0,0 +1,121 @@
1
+ import { getPathParams } from '@kubb/plugin-oas/utils'
2
+ import { File, Function, FunctionParams } from '@kubb/react'
3
+
4
+ import type { ReactNode } from 'react'
5
+
6
+ import { isOptional } from '@kubb/oas'
7
+ import { Client } from '@kubb/plugin-client/components'
8
+ import type { OperationSchemas } from '@kubb/plugin-oas'
9
+ import type { Infinite, PluginReactQuery } from '../types.ts'
10
+ import { QueryKey } from './QueryKey.tsx'
11
+
12
+ type Props = {
13
+ name: string
14
+ clientName: string
15
+ queryKeyName: string
16
+ typeSchemas: OperationSchemas
17
+ pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
18
+ dataReturnType: PluginReactQuery['resolvedOptions']['client']['dataReturnType']
19
+ initialPageParam: Infinite['initialPageParam']
20
+ cursorParam: Infinite['cursorParam']
21
+ queryParam: Infinite['queryParam']
22
+ }
23
+
24
+ type GetParamsProps = {
25
+ pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
26
+ typeSchemas: OperationSchemas
27
+ }
28
+
29
+ function getParams({ pathParamsType, typeSchemas }: GetParamsProps) {
30
+ return FunctionParams.factory({
31
+ pathParams: {
32
+ mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
33
+ children: getPathParams(typeSchemas.pathParams, { typed: true }),
34
+ },
35
+ data: typeSchemas.request?.name
36
+ ? {
37
+ type: typeSchemas.request?.name,
38
+ optional: isOptional(typeSchemas.request?.schema),
39
+ }
40
+ : undefined,
41
+ params: typeSchemas.queryParams?.name
42
+ ? {
43
+ type: typeSchemas.queryParams?.name,
44
+ optional: isOptional(typeSchemas.queryParams?.schema),
45
+ }
46
+ : undefined,
47
+ headers: typeSchemas.headerParams?.name
48
+ ? {
49
+ type: typeSchemas.headerParams?.name,
50
+ optional: isOptional(typeSchemas.headerParams?.schema),
51
+ }
52
+ : undefined,
53
+ config: {
54
+ type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : 'Partial<RequestConfig>',
55
+ default: '{}',
56
+ },
57
+ })
58
+ }
59
+
60
+ export function InfiniteQueryOptions({
61
+ name,
62
+ clientName,
63
+ initialPageParam,
64
+ cursorParam,
65
+ typeSchemas,
66
+ dataReturnType,
67
+ pathParamsType,
68
+ queryParam,
69
+ queryKeyName,
70
+ }: Props): ReactNode {
71
+ const params = getParams({ pathParamsType, typeSchemas })
72
+ const clientParams = Client.getParams({
73
+ typeSchemas,
74
+ pathParamsType,
75
+ })
76
+ const queryKeyParams = QueryKey.getParams({
77
+ pathParamsType,
78
+ typeSchemas,
79
+ })
80
+
81
+ const queryOptions = [
82
+ `initialPageParam: ${typeof initialPageParam === 'string' ? JSON.stringify(initialPageParam) : initialPageParam}`,
83
+ cursorParam ? `getNextPageParam: (lastPage) => lastPage['${cursorParam}']` : undefined,
84
+ cursorParam ? `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']` : undefined,
85
+ !cursorParam && dataReturnType === 'full'
86
+ ? 'getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1'
87
+ : undefined,
88
+ !cursorParam && dataReturnType === 'data'
89
+ ? 'getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1'
90
+ : undefined,
91
+ !cursorParam ? 'getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1' : undefined,
92
+ ].filter(Boolean)
93
+
94
+ const infiniteOverrideParams =
95
+ queryParam && typeSchemas.queryParams?.name
96
+ ? `
97
+ if(params) {
98
+ params['${queryParam}'] = pageParam as unknown as ${typeSchemas.queryParams?.name}['${queryParam}']
99
+ }`
100
+ : ''
101
+
102
+ return (
103
+ <File.Source name={name} isExportable isIndexable>
104
+ <Function name={name} export params={params.toConstructor()}>
105
+ {`
106
+ const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})
107
+ return infiniteQueryOptions({
108
+ queryKey,
109
+ queryFn: async ({ pageParam }) => {
110
+ ${infiniteOverrideParams}
111
+ return ${clientName}(${clientParams.toCall()})
112
+ },
113
+ ${queryOptions.join('\n')}
114
+ })
115
+ `}
116
+ </Function>
117
+ </File.Source>
118
+ )
119
+ }
120
+
121
+ InfiniteQueryOptions.getParams = getParams
@@ -1,325 +1,133 @@
1
- import transformers from '@kubb/core/transformers'
2
- import { FunctionParams, URLPath } from '@kubb/core/utils'
3
- import { useOperation, useOperationManager } from '@kubb/plugin-oas/hooks'
4
- import { getASTParams, getComments } from '@kubb/plugin-oas/utils'
5
- import { pluginTsName } from '@kubb/plugin-ts'
6
- import { File, Function, useApp } from '@kubb/react'
1
+ import { File, Function, FunctionParams } from '@kubb/react'
7
2
 
8
- import { SchemaType } from './SchemaType.tsx'
3
+ import { type Operation, isOptional } from '@kubb/oas'
4
+ import { Client } from '@kubb/plugin-client/components'
5
+ import type { OperationSchemas } from '@kubb/plugin-oas'
6
+ import { getComments, getPathParams } from '@kubb/plugin-oas/utils'
7
+ import type { ReactNode } from 'react'
8
+ import type { PluginReactQuery } from '../types.ts'
9
9
 
10
- import { isRequired } from '@kubb/oas'
11
- import type { HttpMethod } from '@kubb/oas'
12
- import type { ComponentProps, ComponentType, ReactNode } from 'react'
13
- import type { FileMeta, PluginReactQuery } from '../types.ts'
14
-
15
- type TemplateProps = {
10
+ type Props = {
16
11
  /**
17
12
  * Name of the function
18
13
  */
19
14
  name: string
20
- /**
21
- * Parameters/options/props that need to be used
22
- */
23
- params: string
24
- mutateParams: string
25
- /**
26
- * Options for JSdocs
27
- */
28
- JSDoc?: {
29
- comments: string[]
30
- }
31
- hook: {
32
- name: string
33
- generics?: string
34
- children?: string
35
- }
36
- client: {
37
- generics: string
38
- method: HttpMethod
39
- path: URLPath
40
- withQueryParams: boolean
41
- withPathParams: boolean
42
- withData: boolean
43
- withHeaders: boolean
44
- contentType: string
45
- }
46
- dataReturnType: NonNullable<PluginReactQuery['options']['dataReturnType']>
15
+ typeName: string
16
+ clientName: string
17
+ typeSchemas: OperationSchemas
18
+ operation: Operation
19
+ dataReturnType: PluginReactQuery['resolvedOptions']['client']['dataReturnType']
20
+ pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
47
21
  }
48
22
 
49
- function Template({ name, params, mutateParams, JSDoc, client, hook, dataReturnType }: TemplateProps): ReactNode {
50
- const isFormData = client.contentType === 'multipart/form-data'
51
- const headers = [
52
- client.contentType !== 'application/json' ? `'Content-Type': '${client.contentType}'` : undefined,
53
- client.withHeaders ? '...headers' : undefined,
54
- ]
55
- .filter(Boolean)
56
- .join(', ')
57
-
58
- const clientOptions = [
59
- `method: "${client.method}"`,
60
- `url: ${client.path.template}`,
61
- client.withQueryParams ? 'params' : undefined,
62
- client.withData && !isFormData ? 'data' : undefined,
63
- client.withData && isFormData ? 'data: formData' : undefined,
64
- headers.length ? `headers: { ${headers}, ...clientOptions.headers }` : undefined,
65
- '...clientOptions',
66
- ].filter(Boolean)
67
-
68
- const resolvedClientOptions = `${transformers.createIndent(4)}${clientOptions.join(`,\n${transformers.createIndent(4)}`)}`
69
-
70
- const formData = isFormData
71
- ? `
72
- const formData = new FormData()
73
- if(data) {
74
- Object.keys(data).forEach((key) => {
75
- const value = data[key];
76
- if (typeof key === "string" && (typeof value === "string" || value instanceof Blob)) {
77
- formData.append(key, value);
78
- }
79
- })
80
- }
81
- `
82
- : undefined
83
-
84
- return (
85
- <File.Source name={name} isExportable isIndexable>
86
- <Function export name={name} params={params} JSDoc={JSDoc}>
87
- {`
88
- const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
89
-
90
- return ${hook.name}({
91
- mutationFn: async(${mutateParams}) => {
92
- ${hook.children || ''}
93
- ${formData || ''}
94
- const res = await client<${client.generics}>({
95
- ${resolvedClientOptions}
96
- })
97
-
98
- return ${dataReturnType === 'data' ? 'res.data' : 'res'}
99
- },
100
- ...mutationOptions
101
- })`}
102
- </Function>
103
- </File.Source>
104
- )
23
+ type GetParamsProps = {
24
+ pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
25
+ dataReturnType: PluginReactQuery['resolvedOptions']['client']['dataReturnType']
26
+ typeSchemas: OperationSchemas
105
27
  }
106
28
 
107
- type RootTemplateProps = {
108
- children?: React.ReactNode
29
+ function getParams({ dataReturnType, typeSchemas }: GetParamsProps) {
30
+ const mutateParams = FunctionParams.factory({
31
+ ...getPathParams(typeSchemas.pathParams, { typed: true }),
32
+ data: typeSchemas.request?.name
33
+ ? {
34
+ type: typeSchemas.request?.name,
35
+ optional: isOptional(typeSchemas.request?.schema),
36
+ }
37
+ : undefined,
38
+ params: typeSchemas.queryParams?.name
39
+ ? {
40
+ type: typeSchemas.queryParams?.name,
41
+ optional: isOptional(typeSchemas.queryParams?.schema),
42
+ }
43
+ : undefined,
44
+ headers: typeSchemas.headerParams?.name
45
+ ? {
46
+ type: typeSchemas.headerParams?.name,
47
+ optional: isOptional(typeSchemas.headerParams?.schema),
48
+ }
49
+ : undefined,
50
+ })
51
+
52
+ const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
53
+ const TRequest = mutateParams.toConstructor({ valueAsType: true })
54
+
55
+ return FunctionParams.factory({
56
+ options: {
57
+ type: `
58
+ {
59
+ mutation?: UseMutationOptions<${[TData, typeSchemas.errors?.map((item) => item.name).join(' | ') || 'unknown', `{${TRequest}`].join(', ')}>,
60
+ client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : 'Partial<RequestConfig>'},
109
61
  }
110
-
111
- function RootTemplate({ children }: RootTemplateProps) {
112
- const {
113
- plugin: {
114
- options: {
115
- client: { importPath },
116
- mutate,
117
- },
62
+ `,
63
+ default: '{}',
118
64
  },
119
- } = useApp<PluginReactQuery>()
120
-
121
- const { getFile } = useOperationManager()
122
- const operation = useOperation()
123
- const file = getFile(operation)
124
-
125
- return (
126
- <File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>
127
- <File.Import name={'client'} path={importPath} />
128
-
129
- <File.Import
130
- name={['UseMutationOptions']}
131
- path={typeof mutate !== 'boolean' && mutate.importPath ? mutate.importPath : '@tanstack/react-query'}
132
- isTypeOnly
133
- />
134
- <File.Import name={['useMutation']} path={typeof mutate !== 'boolean' && mutate.importPath ? mutate.importPath : '@tanstack/react-query'} />
135
- {children}
136
- </File>
137
- )
138
- }
139
-
140
- const defaultTemplates = { default: Template, root: RootTemplate } as const
141
-
142
- type Templates = Partial<typeof defaultTemplates>
143
-
144
- type MutationProps = {
145
- /**
146
- * This will make it possible to override the default behaviour.
147
- */
148
- Template?: ComponentType<ComponentProps<typeof Template>>
65
+ })
149
66
  }
150
67
 
151
- export function Mutation({ Template = defaultTemplates.default }: MutationProps): ReactNode {
152
- // TODO do checks on pathParamsType
153
-
154
- const {
155
- plugin: {
156
- options: { dataReturnType, mutate },
157
- },
158
- } = useApp<PluginReactQuery>()
159
-
160
- const operation = useOperation()
161
- const { getSchemas, getName } = useOperationManager()
162
-
163
- const name = getName(operation, { type: 'function' })
164
- const schemas = getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' })
165
- const contentType = operation.getContentType()
166
-
167
- const params = new FunctionParams()
168
- const mutateParams = new FunctionParams()
169
- const factoryName = getName(operation, { type: 'type' })
170
-
171
- const requestType =
172
- mutate && mutate.variablesType === 'mutate'
173
- ? FunctionParams.toObject([
174
- ...getASTParams(schemas.pathParams, { typed: true }),
175
- {
176
- name: 'params',
177
- type: `${factoryName}['queryParams']`,
178
- enabled: !!schemas.queryParams?.name,
179
- required: isRequired(schemas.queryParams?.schema),
180
- },
181
- {
182
- name: 'headers',
183
- type: `${factoryName}['headerParams']`,
184
- enabled: !!schemas.headerParams?.name,
185
- required: isRequired(schemas.headerParams?.schema),
186
- },
187
- {
188
- name: 'data',
189
- type: `${factoryName}['request']`,
190
- enabled: !!schemas.request?.name,
191
- required: isRequired(schemas.request?.schema),
192
- },
193
- ])?.type
194
- : schemas.request?.name
195
- ? `${factoryName}['request']`
196
- : 'never'
197
-
198
- const client = {
199
- method: operation.method,
200
- path: new URLPath(operation.path),
201
- generics: [`${factoryName}["data"]`, `${factoryName}["error"]`, requestType ? `${factoryName}["request"]` : 'void'].join(', '),
202
- withQueryParams: !!schemas.queryParams?.name,
203
- withData: !!schemas.request?.name,
204
- withPathParams: !!schemas.pathParams?.name,
205
- withHeaders: !!schemas.headerParams?.name,
206
- contentType,
207
- }
208
- const hook = {
209
- name: 'useMutation',
210
- generics: [`${factoryName}['response']`, `${factoryName}["error"]`, requestType ? `${requestType}` : 'void'].join(', '),
211
- }
212
-
213
- const resultGenerics = [
214
- `${factoryName}["response"]`,
215
- `${factoryName}["error"]`,
216
- mutate && mutate?.variablesType === 'mutate' ? requestType : `${factoryName}["request"]`,
217
- ]
218
-
219
- if (mutate && mutate?.variablesType === 'mutate') {
220
- params.add([
221
- {
222
- name: 'options',
223
- type: `{
224
- mutation?: UseMutationOptions<${resultGenerics.join(', ')}>,
225
- client?: ${factoryName}['client']['parameters']
226
- }`,
227
- default: '{}',
228
- },
229
- ])
230
-
231
- mutateParams.add([
232
- [
233
- ...getASTParams(schemas.pathParams, { typed: false }),
234
- {
235
- name: 'params',
236
- enabled: client.withQueryParams,
237
- required: isRequired(schemas.queryParams?.schema),
238
- },
239
- {
240
- name: 'headers',
241
- enabled: client.withHeaders,
242
- required: isRequired(schemas.headerParams?.schema),
243
- },
244
- {
245
- name: 'data',
246
- enabled: !!schemas.request?.name,
247
- required: isRequired(schemas.request?.schema),
248
- },
249
- ],
250
- ])
251
- } else {
252
- params.add([
253
- ...getASTParams(schemas.pathParams, { typed: true }),
254
- {
255
- name: 'params',
256
- type: `${factoryName}['queryParams']`,
257
- enabled: client.withQueryParams,
258
- required: isRequired(schemas.queryParams?.schema),
259
- },
260
- {
261
- name: 'headers',
262
- type: `${factoryName}['headerParams']`,
263
- enabled: client.withHeaders,
264
- required: isRequired(schemas.headerParams?.schema),
68
+ export function Mutation({ name, clientName, pathParamsType, dataReturnType, typeSchemas, operation }: Props): ReactNode {
69
+ const params = getParams({
70
+ pathParamsType,
71
+ dataReturnType,
72
+ typeSchemas,
73
+ })
74
+
75
+ const clientParams = Client.getParams({
76
+ typeSchemas,
77
+ pathParamsType,
78
+ })
79
+
80
+ const mutationParams = FunctionParams.factory({
81
+ data: {
82
+ // No use of pathParams because useMutation can only take one argument in object form,
83
+ // see https://tanstack.com/query/latest/docs/framework/react/reference/useMutation#usemutation
84
+ mode: 'object',
85
+ //TODO rename with value
86
+ children: {
87
+ ...getPathParams(typeSchemas.pathParams, { typed: true }),
88
+ data: typeSchemas.request?.name
89
+ ? {
90
+ type: typeSchemas.request?.name,
91
+ optional: isOptional(typeSchemas.request?.schema),
92
+ }
93
+ : undefined,
94
+ params: typeSchemas.queryParams?.name
95
+ ? {
96
+ type: typeSchemas.queryParams?.name,
97
+ optional: isOptional(typeSchemas.queryParams?.schema),
98
+ }
99
+ : undefined,
100
+ headers: typeSchemas.headerParams?.name
101
+ ? {
102
+ type: typeSchemas.headerParams?.name,
103
+ optional: isOptional(typeSchemas.headerParams?.schema),
104
+ }
105
+ : undefined,
265
106
  },
266
- {
267
- name: 'options',
268
- type: `{
269
- mutation?: UseMutationOptions<${resultGenerics.join(', ')}>,
270
- client?: ${factoryName}['client']['parameters']
271
- }`,
272
- default: '{}',
273
- },
274
- ])
275
-
276
- mutateParams.add([
277
- {
278
- name: 'data',
279
- enabled: !!schemas.request?.name,
280
- required: isRequired(schemas.request?.schema),
281
- },
282
- ])
283
- }
284
-
285
- if (!mutate) {
286
- return null
287
- }
107
+ },
108
+ })
288
109
 
289
110
  return (
290
- <>
291
- <Template
111
+ <File.Source name={name} isExportable isIndexable>
112
+ <Function
292
113
  name={name}
293
- JSDoc={{ comments: getComments(operation) }}
294
- client={client}
295
- hook={hook}
296
- params={params.toString()}
297
- mutateParams={mutateParams.toString()}
298
- dataReturnType={dataReturnType}
299
- />
300
- </>
301
- )
302
- }
303
-
304
- type FileProps = {
305
- /**
306
- * This will make it possible to override the default behaviour.
307
- */
308
- templates?: Templates
309
- }
310
-
311
- Mutation.File = function ({ ...props }: FileProps): ReactNode {
312
- const templates = { ...defaultTemplates, ...props.templates }
313
-
314
- const Template = templates.default
315
- const RootTemplate = templates.root
114
+ export
115
+ params={params.toConstructor()}
116
+ JSDoc={{
117
+ comments: getComments(operation),
118
+ }}
119
+ >
120
+ {`
121
+ const { mutation: mutationOptions, client: config = {} } = options ?? {}
316
122
 
317
- return (
318
- <RootTemplate>
319
- <SchemaType />
320
- <Mutation Template={Template} />
321
- </RootTemplate>
123
+ return useMutation({
124
+ mutationFn: async(${mutationParams.toConstructor()}) => {
125
+ return ${clientName}(${clientParams.toCall()})
126
+ },
127
+ ...mutationOptions
128
+ })
129
+ `}
130
+ </Function>
131
+ </File.Source>
322
132
  )
323
133
  }
324
-
325
- Mutation.templates = defaultTemplates