@kubb/plugin-react-query 3.0.0-alpha.2 → 3.0.0-alpha.21

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 (80) hide show
  1. package/README.md +13 -4
  2. package/dist/chunk-ESENIDWJ.js +608 -0
  3. package/dist/chunk-ESENIDWJ.js.map +1 -0
  4. package/dist/chunk-HAC4WPCC.js +608 -0
  5. package/dist/chunk-HAC4WPCC.js.map +1 -0
  6. package/dist/chunk-JQEH3UHY.cjs +618 -0
  7. package/dist/chunk-JQEH3UHY.cjs.map +1 -0
  8. package/dist/chunk-JYBGTT23.cjs +618 -0
  9. package/dist/chunk-JYBGTT23.cjs.map +1 -0
  10. package/dist/components.cjs +35 -14
  11. package/dist/components.cjs.map +1 -1
  12. package/dist/components.d.cts +143 -7
  13. package/dist/components.d.ts +143 -7
  14. package/dist/components.js +2 -14
  15. package/dist/components.js.map +1 -1
  16. package/dist/generators.cjs +25 -0
  17. package/dist/generators.cjs.map +1 -0
  18. package/dist/generators.d.cts +14 -0
  19. package/dist/generators.d.ts +14 -0
  20. package/dist/generators.js +4 -0
  21. package/dist/generators.js.map +1 -0
  22. package/dist/index.cjs +77 -154
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +1 -5
  25. package/dist/index.d.ts +1 -5
  26. package/dist/index.js +56 -140
  27. package/dist/index.js.map +1 -1
  28. package/dist/types-DFHc63S9.d.cts +179 -0
  29. package/dist/types-DFHc63S9.d.ts +179 -0
  30. package/package.json +22 -17
  31. package/src/components/InfiniteQuery.tsx +129 -0
  32. package/src/components/InfiniteQueryOptions.tsx +121 -0
  33. package/src/components/Mutation.tsx +113 -321
  34. package/src/components/Query.tsx +91 -598
  35. package/src/components/QueryKey.tsx +51 -178
  36. package/src/components/QueryOptions.tsx +65 -468
  37. package/src/components/SuspenseQuery.tsx +129 -0
  38. package/src/components/index.ts +3 -1
  39. package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +50 -0
  40. package/src/generators/__snapshots__/clientGetImportPath.ts +50 -0
  41. package/src/generators/__snapshots__/clientPostImportPath.ts +38 -0
  42. package/src/generators/__snapshots__/findByTags.ts +50 -0
  43. package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +50 -0
  44. package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +50 -0
  45. package/src/generators/__snapshots__/findByTagsWithZod.ts +50 -0
  46. package/src/generators/__snapshots__/findInfiniteByTags.ts +56 -0
  47. package/src/generators/__snapshots__/findInfiniteByTagsCursor.ts +56 -0
  48. package/src/generators/__snapshots__/getAsMutation.ts +31 -0
  49. package/src/generators/__snapshots__/postAsQuery.ts +48 -0
  50. package/src/generators/__snapshots__/updatePetById.ts +38 -0
  51. package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +40 -0
  52. package/src/generators/index.ts +4 -0
  53. package/src/generators/infiniteQueryGenerator.tsx +125 -0
  54. package/src/generators/mutationGenerator.tsx +96 -0
  55. package/src/generators/queryGenerator.tsx +122 -0
  56. package/src/generators/suspenseQueryGenerator.tsx +121 -0
  57. package/src/plugin.ts +51 -73
  58. package/src/types.ts +43 -91
  59. package/dist/chunk-5IL6M74X.js +0 -1504
  60. package/dist/chunk-5IL6M74X.js.map +0 -1
  61. package/dist/chunk-JFX7DCS7.cjs +0 -1504
  62. package/dist/chunk-JFX7DCS7.cjs.map +0 -1
  63. package/dist/index-C9fwRDH7.d.cts +0 -579
  64. package/dist/index-C9fwRDH7.d.ts +0 -579
  65. package/src/OperationGenerator.tsx +0 -86
  66. package/src/__snapshots__/mutateAsQuery/updatePetWithForm.ts +0 -64
  67. package/src/__snapshots__/pathParamsTypeInline/getPetById.ts +0 -57
  68. package/src/__snapshots__/pathParamsTypeObject/getPetById.ts +0 -63
  69. package/src/__snapshots__/queryOptions/getPetById.ts +0 -37
  70. package/src/__snapshots__/queryWithoutQueryOptions/getPetById.ts +0 -47
  71. package/src/__snapshots__/upload/UploadFile.ts +0 -67
  72. package/src/__snapshots__/uploadMutation/UploadFile.ts +0 -44
  73. package/src/__snapshots__/variablesTypeMutate/deletePet.ts +0 -21
  74. package/src/components/Operations.tsx +0 -74
  75. package/src/components/QueryImports.tsx +0 -167
  76. package/src/components/SchemaType.tsx +0 -55
  77. package/src/components/__snapshots__/gen/showPetById.ts +0 -57
  78. package/src/components/__snapshots__/gen/useCreatePets.ts +0 -46
  79. package/src/components/__snapshots__/gen/useCreatePetsMutate.ts +0 -47
  80. package/src/utils.ts +0 -96
@@ -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,341 +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 { File, Function, Parser, useApp } from '@kubb/react'
6
- import { pluginTsName } from '@kubb/plugin-ts'
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
- <Function export name={name} params={params} JSDoc={JSDoc}>
86
- {`
87
- const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
88
-
89
- return ${hook.name}({
90
- mutationFn: async(${mutateParams}) => {
91
- ${hook.children || ''}
92
- ${formData || ''}
93
- const res = await client<${client.generics}>({
94
- ${resolvedClientOptions}
95
- })
96
-
97
- return ${dataReturnType === 'data' ? 'res.data' : 'res'}
98
- },
99
- ...mutationOptions
100
- })`}
101
- </Function>
102
- )
23
+ type GetParamsProps = {
24
+ pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
25
+ dataReturnType: PluginReactQuery['resolvedOptions']['client']['dataReturnType']
26
+ typeSchemas: OperationSchemas
103
27
  }
104
28
 
105
- type RootTemplateProps = {
106
- 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>'},
107
61
  }
108
-
109
- function RootTemplate({ children }: RootTemplateProps) {
110
- const {
111
- plugin: {
112
- options: {
113
- client: { importPath },
114
- mutate,
115
- },
62
+ `,
63
+ default: '{}',
116
64
  },
117
- } = useApp<PluginReactQuery>()
118
-
119
- const { getSchemas, getFile } = useOperationManager()
120
- const operation = useOperation()
121
-
122
- const schemas = getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' })
123
- const file = getFile(operation)
124
- const fileType = getFile(operation, { pluginKey: [pluginTsName] })
125
-
126
- return (
127
- <Parser language="typescript">
128
- <File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>
129
- <File.Import name={'client'} path={importPath} />
130
- <File.Import name={['ResponseConfig']} path={importPath} isTypeOnly />
131
- <File.Import
132
- name={[
133
- schemas.request?.name,
134
- schemas.response.name,
135
- schemas.pathParams?.name,
136
- schemas.queryParams?.name,
137
- schemas.headerParams?.name,
138
- ...(schemas.errors?.map((error) => error.name) || []),
139
- ].filter(Boolean)}
140
- root={file.path}
141
- path={fileType.path}
142
- isTypeOnly
143
- />
144
- <File.Import
145
- name={['UseMutationOptions', 'UseMutationResult']}
146
- path={typeof mutate !== 'boolean' && mutate.importPath ? mutate.importPath : '@tanstack/react-query'}
147
- isTypeOnly
148
- />
149
- <File.Import name={['useMutation']} path={typeof mutate !== 'boolean' && mutate.importPath ? mutate.importPath : '@tanstack/react-query'} />
150
- <File.Source>{children}</File.Source>
151
- </File>
152
- </Parser>
153
- )
154
- }
155
-
156
- const defaultTemplates = { default: Template, root: RootTemplate } as const
157
-
158
- type Templates = Partial<typeof defaultTemplates>
159
-
160
- type MutationProps = {
161
- /**
162
- * This will make it possible to override the default behaviour.
163
- */
164
- Template?: ComponentType<ComponentProps<typeof Template>>
65
+ })
165
66
  }
166
67
 
167
- export function Mutation({ Template = defaultTemplates.default }: MutationProps): ReactNode {
168
- // TODO do checks on pathParamsType
169
-
170
- const {
171
- plugin: {
172
- options: { dataReturnType, mutate },
173
- },
174
- } = useApp<PluginReactQuery>()
175
-
176
- const operation = useOperation()
177
- const { getSchemas, getName } = useOperationManager()
178
-
179
- const name = getName(operation, { type: 'function' })
180
- const schemas = getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' })
181
- const contentType = operation.getContentType()
182
-
183
- const params = new FunctionParams()
184
- const mutateParams = new FunctionParams()
185
- const factoryName = getName(operation, { type: 'type' })
186
-
187
- const requestType =
188
- mutate && mutate.variablesType === 'mutate'
189
- ? FunctionParams.toObject([
190
- ...getASTParams(schemas.pathParams, { typed: true }),
191
- {
192
- name: 'params',
193
- type: `${factoryName}['queryParams']`,
194
- enabled: !!schemas.queryParams?.name,
195
- required: isRequired(schemas.queryParams?.schema),
196
- },
197
- {
198
- name: 'headers',
199
- type: `${factoryName}['headerParams']`,
200
- enabled: !!schemas.headerParams?.name,
201
- required: isRequired(schemas.headerParams?.schema),
202
- },
203
- {
204
- name: 'data',
205
- type: `${factoryName}['request']`,
206
- enabled: !!schemas.request?.name,
207
- required: isRequired(schemas.request?.schema),
208
- },
209
- ])?.type
210
- : schemas.request?.name
211
- ? `${factoryName}['request']`
212
- : 'never'
213
-
214
- const client = {
215
- method: operation.method,
216
- path: new URLPath(operation.path),
217
- generics: [`${factoryName}["data"]`, `${factoryName}["error"]`, requestType ? `${factoryName}["request"]` : 'void'].join(', '),
218
- withQueryParams: !!schemas.queryParams?.name,
219
- withData: !!schemas.request?.name,
220
- withPathParams: !!schemas.pathParams?.name,
221
- withHeaders: !!schemas.headerParams?.name,
222
- contentType,
223
- }
224
- const hook = {
225
- name: 'useMutation',
226
- generics: [`${factoryName}['response']`, `${factoryName}["error"]`, requestType ? `${requestType}` : 'void'].join(', '),
227
- }
228
-
229
- const resultGenerics = [
230
- `${factoryName}["response"]`,
231
- `${factoryName}["error"]`,
232
- mutate && mutate?.variablesType === 'mutate' ? requestType : `${factoryName}["request"]`,
233
- ]
234
-
235
- if (mutate && mutate?.variablesType === 'mutate') {
236
- params.add([
237
- {
238
- name: 'options',
239
- type: `{
240
- mutation?: UseMutationOptions<${resultGenerics.join(', ')}>,
241
- client?: ${factoryName}['client']['parameters']
242
- }`,
243
- default: '{}',
244
- },
245
- ])
246
-
247
- mutateParams.add([
248
- [
249
- ...getASTParams(schemas.pathParams, { typed: false }),
250
- {
251
- name: 'params',
252
- enabled: client.withQueryParams,
253
- required: isRequired(schemas.queryParams?.schema),
254
- },
255
- {
256
- name: 'headers',
257
- enabled: client.withHeaders,
258
- required: isRequired(schemas.headerParams?.schema),
259
- },
260
- {
261
- name: 'data',
262
- enabled: !!schemas.request?.name,
263
- required: isRequired(schemas.request?.schema),
264
- },
265
- ],
266
- ])
267
- } else {
268
- params.add([
269
- ...getASTParams(schemas.pathParams, { typed: true }),
270
- {
271
- name: 'params',
272
- type: `${factoryName}['queryParams']`,
273
- enabled: client.withQueryParams,
274
- required: isRequired(schemas.queryParams?.schema),
275
- },
276
- {
277
- name: 'headers',
278
- type: `${factoryName}['headerParams']`,
279
- enabled: client.withHeaders,
280
- required: isRequired(schemas.headerParams?.schema),
281
- },
282
- {
283
- name: 'options',
284
- type: `{
285
- mutation?: UseMutationOptions<${resultGenerics.join(', ')}>,
286
- client?: ${factoryName}['client']['parameters']
287
- }`,
288
- default: '{}',
289
- },
290
- ])
291
-
292
- mutateParams.add([
293
- {
294
- name: 'data',
295
- enabled: !!schemas.request?.name,
296
- required: isRequired(schemas.request?.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,
297
106
  },
298
- ])
299
- }
300
-
301
- if (!mutate) {
302
- return null
303
- }
107
+ },
108
+ })
304
109
 
305
110
  return (
306
- <>
307
- <Template
111
+ <File.Source name={name} isExportable isIndexable>
112
+ <Function
308
113
  name={name}
309
- JSDoc={{ comments: getComments(operation) }}
310
- client={client}
311
- hook={hook}
312
- params={params.toString()}
313
- mutateParams={mutateParams.toString()}
314
- dataReturnType={dataReturnType}
315
- />
316
- </>
317
- )
318
- }
319
-
320
- type FileProps = {
321
- /**
322
- * This will make it possible to override the default behaviour.
323
- */
324
- templates?: Templates
325
- }
326
-
327
- Mutation.File = function ({ ...props }: FileProps): ReactNode {
328
- const templates = { ...defaultTemplates, ...props.templates }
329
-
330
- const Template = templates.default
331
- const RootTemplate = templates.root
332
-
333
- return (
334
- <RootTemplate>
335
- <SchemaType />
336
- <Mutation Template={Template} />
337
- </RootTemplate>
114
+ export
115
+ params={params.toConstructor()}
116
+ JSDoc={{
117
+ comments: getComments(operation),
118
+ }}
119
+ >
120
+ {`
121
+ const { mutation: mutationOptions, client: config = {} } = options ?? {}
122
+
123
+ return useMutation({
124
+ mutationFn: async(${mutationParams.toConstructor()}) => {
125
+ return ${clientName}(${clientParams.toCall()})
126
+ },
127
+ ...mutationOptions
128
+ })
129
+ `}
130
+ </Function>
131
+ </File.Source>
338
132
  )
339
133
  }
340
-
341
- Mutation.templates = defaultTemplates