Skip to content

Commit 70c8ee9

Browse files
committed
feat: Support generating mutations with @kubb/plugin-solid-query
1 parent fff3382 commit 70c8ee9

37 files changed

+1393
-50
lines changed

.changeset/whole-pants-beam.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@kubb/plugin-solid-query": patch
3+
---
4+
5+
Support generating mutations with @kubb/plugin-solid-query

examples/solid-query/src/gen/hooks/createUpdatePetWithForm.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type {
1212
} from '../models/UpdatePetWithForm.ts'
1313
import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/axios'
1414
import type { QueryKey, QueryClient, UseBaseQueryOptions, UseQueryResult } from '@tanstack/solid-query'
15-
import { queryOptions, createQuery } from '@tanstack/solid-query'
15+
import { queryOptions, useQuery } from '@tanstack/solid-query'
1616

1717
export const updatePetWithFormQueryKey = (petId: UpdatePetWithFormPathParams['petId'], params?: UpdatePetWithFormQueryParams) =>
1818
[{ url: '/pet/:petId', params: { petId: petId } }, ...(params ? [params] : [])] as const
@@ -77,7 +77,7 @@ export function createUpdatePetWithForm<
7777
const { client: queryClient, ...queryOptions } = queryConfig
7878
const queryKey = queryOptions?.queryKey ?? updatePetWithFormQueryKey(petId, params)
7979

80-
const query = createQuery(
80+
const query = useQuery(
8181
() => ({
8282
...(updatePetWithFormQueryOptions(petId, params, config) as unknown as UseBaseQueryOptions),
8383
queryKey,

examples/solid-query/src/gen/hooks/index.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ export type { GetUserByNameQueryKey } from './createGetUserByName.ts'
77
export type { LoginUserQueryKey } from './createLoginUser.ts'
88
export type { LogoutUserQueryKey } from './createLogoutUser.ts'
99
export type { UpdatePetWithFormQueryKey } from './createUpdatePetWithForm.ts'
10+
export type { AddPetMutationKey } from './useAddPet.ts'
11+
export type { CreateUserMutationKey } from './useCreateUser.ts'
12+
export type { CreateUsersWithListInputMutationKey } from './useCreateUsersWithListInput.ts'
13+
export type { DeleteOrderMutationKey } from './useDeleteOrder.ts'
14+
export type { DeletePetMutationKey } from './useDeletePet.ts'
15+
export type { DeleteUserMutationKey } from './useDeleteUser.ts'
16+
export type { PlaceOrderMutationKey } from './usePlaceOrder.ts'
17+
export type { PlaceOrderPatchMutationKey } from './usePlaceOrderPatch.ts'
18+
export type { UpdatePetMutationKey } from './useUpdatePet.ts'
19+
export type { UpdateUserMutationKey } from './useUpdateUser.ts'
20+
export type { UploadFileMutationKey } from './useUploadFile.ts'
1021
export { findPetsByStatusQueryKey, findPetsByStatus, findPetsByStatusQueryOptions } from './createFindPetsByStatus.ts'
1122
export { findPetsByTagsQueryKey, findPetsByTags, findPetsByTagsQueryOptions } from './createFindPetsByTags.ts'
1223
export { getInventoryQueryKey, getInventory, getInventoryQueryOptions } from './createGetInventory.ts'
@@ -16,3 +27,14 @@ export { getUserByNameQueryKey, getUserByName, getUserByNameQueryOptions } from
1627
export { loginUserQueryKey, loginUser, loginUserQueryOptions } from './createLoginUser.ts'
1728
export { logoutUserQueryKey, logoutUser, logoutUserQueryOptions } from './createLogoutUser.ts'
1829
export { updatePetWithFormQueryKey, updatePetWithForm, updatePetWithFormQueryOptions, createUpdatePetWithForm } from './createUpdatePetWithForm.ts'
30+
export { addPetMutationKey, addPet, useAddPet } from './useAddPet.ts'
31+
export { createUserMutationKey, createUser, useCreateUser } from './useCreateUser.ts'
32+
export { createUsersWithListInputMutationKey, createUsersWithListInput, useCreateUsersWithListInput } from './useCreateUsersWithListInput.ts'
33+
export { deleteOrderMutationKey, deleteOrder, useDeleteOrder } from './useDeleteOrder.ts'
34+
export { deletePetMutationKey, deletePet, useDeletePet } from './useDeletePet.ts'
35+
export { deleteUserMutationKey, deleteUser, useDeleteUser } from './useDeleteUser.ts'
36+
export { placeOrderMutationKey, placeOrder, usePlaceOrder } from './usePlaceOrder.ts'
37+
export { placeOrderPatchMutationKey, placeOrderPatch, usePlaceOrderPatch } from './usePlaceOrderPatch.ts'
38+
export { updatePetMutationKey, updatePet, useUpdatePet } from './useUpdatePet.ts'
39+
export { updateUserMutationKey, updateUser, useUpdateUser } from './useUpdateUser.ts'
40+
export { uploadFileMutationKey, uploadFile, useUploadFile } from './useUploadFile.ts'
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* Generated by Kubb (https://kubb.dev/).
3+
* Do not edit manually.
4+
*/
5+
6+
import fetch from '@kubb/plugin-client/clients/axios'
7+
import type { AddPetMutationRequest, AddPetMutationResponse, AddPet405 } from '../models/AddPet.ts'
8+
import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/axios'
9+
import type { UseMutationOptions, QueryClient } from '@tanstack/solid-query'
10+
import { useMutation } from '@tanstack/solid-query'
11+
12+
export const addPetMutationKey = () => [{ url: '/pet' }] as const
13+
14+
export type AddPetMutationKey = ReturnType<typeof addPetMutationKey>
15+
16+
/**
17+
* @description Add a new pet to the store
18+
* @summary Add a new pet to the store
19+
* {@link /pet}
20+
*/
21+
export async function addPet(data: AddPetMutationRequest, config: Partial<RequestConfig<AddPetMutationRequest>> & { client?: typeof fetch } = {}) {
22+
const { client: request = fetch, ...requestConfig } = config
23+
24+
const requestData = data
25+
26+
const res = await request<AddPetMutationResponse, ResponseErrorConfig<AddPet405>, AddPetMutationRequest>({
27+
method: 'POST',
28+
url: '/pet',
29+
data: requestData,
30+
...requestConfig,
31+
})
32+
return res.data
33+
}
34+
35+
/**
36+
* @description Add a new pet to the store
37+
* @summary Add a new pet to the store
38+
* {@link /pet}
39+
*/
40+
export function useAddPet<TContext>(
41+
options: {
42+
mutation?: ReturnType<UseMutationOptions<AddPetMutationResponse, ResponseErrorConfig<AddPet405>, { data: AddPetMutationRequest }, TContext>> & {
43+
client?: QueryClient
44+
}
45+
client?: Partial<RequestConfig<AddPetMutationRequest>> & { client?: typeof fetch }
46+
} = {},
47+
) {
48+
const { mutation = {}, client: config = {} } = options ?? {}
49+
const { client: queryClient, ...mutationOptions } = mutation
50+
const mutationKey = mutationOptions.mutationKey ?? addPetMutationKey()
51+
52+
return useMutation<AddPetMutationResponse, ResponseErrorConfig<AddPet405>, { data: AddPetMutationRequest }, TContext>(
53+
() => ({
54+
mutationFn: async ({ data }) => {
55+
return addPet(data, config)
56+
},
57+
mutationKey,
58+
...mutationOptions,
59+
}),
60+
queryClient ? () => queryClient : undefined,
61+
)
62+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* Generated by Kubb (https://kubb.dev/).
3+
* Do not edit manually.
4+
*/
5+
6+
import fetch from '@kubb/plugin-client/clients/axios'
7+
import type { CreateUserMutationRequest, CreateUserMutationResponse } from '../models/CreateUser.ts'
8+
import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/axios'
9+
import type { UseMutationOptions, QueryClient } from '@tanstack/solid-query'
10+
import { useMutation } from '@tanstack/solid-query'
11+
12+
export const createUserMutationKey = () => [{ url: '/user' }] as const
13+
14+
export type CreateUserMutationKey = ReturnType<typeof createUserMutationKey>
15+
16+
/**
17+
* @description This can only be done by the logged in user.
18+
* @summary Create user
19+
* {@link /user}
20+
*/
21+
export async function createUser(data?: CreateUserMutationRequest, config: Partial<RequestConfig<CreateUserMutationRequest>> & { client?: typeof fetch } = {}) {
22+
const { client: request = fetch, ...requestConfig } = config
23+
24+
const requestData = data
25+
26+
const res = await request<CreateUserMutationResponse, ResponseErrorConfig<Error>, CreateUserMutationRequest>({
27+
method: 'POST',
28+
url: '/user',
29+
data: requestData,
30+
...requestConfig,
31+
})
32+
return res.data
33+
}
34+
35+
/**
36+
* @description This can only be done by the logged in user.
37+
* @summary Create user
38+
* {@link /user}
39+
*/
40+
export function useCreateUser<TContext>(
41+
options: {
42+
mutation?: ReturnType<UseMutationOptions<CreateUserMutationResponse, ResponseErrorConfig<Error>, { data?: CreateUserMutationRequest }, TContext>> & {
43+
client?: QueryClient
44+
}
45+
client?: Partial<RequestConfig<CreateUserMutationRequest>> & { client?: typeof fetch }
46+
} = {},
47+
) {
48+
const { mutation = {}, client: config = {} } = options ?? {}
49+
const { client: queryClient, ...mutationOptions } = mutation
50+
const mutationKey = mutationOptions.mutationKey ?? createUserMutationKey()
51+
52+
return useMutation<CreateUserMutationResponse, ResponseErrorConfig<Error>, { data?: CreateUserMutationRequest }, TContext>(
53+
() => ({
54+
mutationFn: async ({ data }) => {
55+
return createUser(data, config)
56+
},
57+
mutationKey,
58+
...mutationOptions,
59+
}),
60+
queryClient ? () => queryClient : undefined,
61+
)
62+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* Generated by Kubb (https://kubb.dev/).
3+
* Do not edit manually.
4+
*/
5+
6+
import fetch from '@kubb/plugin-client/clients/axios'
7+
import type { CreateUsersWithListInputMutationRequest, CreateUsersWithListInputMutationResponse } from '../models/CreateUsersWithListInput.ts'
8+
import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/axios'
9+
import type { UseMutationOptions, QueryClient } from '@tanstack/solid-query'
10+
import { useMutation } from '@tanstack/solid-query'
11+
12+
export const createUsersWithListInputMutationKey = () => [{ url: '/user/createWithList' }] as const
13+
14+
export type CreateUsersWithListInputMutationKey = ReturnType<typeof createUsersWithListInputMutationKey>
15+
16+
/**
17+
* @description Creates list of users with given input array
18+
* @summary Creates list of users with given input array
19+
* {@link /user/createWithList}
20+
*/
21+
export async function createUsersWithListInput(
22+
data?: CreateUsersWithListInputMutationRequest,
23+
config: Partial<RequestConfig<CreateUsersWithListInputMutationRequest>> & { client?: typeof fetch } = {},
24+
) {
25+
const { client: request = fetch, ...requestConfig } = config
26+
27+
const requestData = data
28+
29+
const res = await request<CreateUsersWithListInputMutationResponse, ResponseErrorConfig<Error>, CreateUsersWithListInputMutationRequest>({
30+
method: 'POST',
31+
url: '/user/createWithList',
32+
data: requestData,
33+
...requestConfig,
34+
})
35+
return res.data
36+
}
37+
38+
/**
39+
* @description Creates list of users with given input array
40+
* @summary Creates list of users with given input array
41+
* {@link /user/createWithList}
42+
*/
43+
export function useCreateUsersWithListInput<TContext>(
44+
options: {
45+
mutation?: ReturnType<
46+
UseMutationOptions<CreateUsersWithListInputMutationResponse, ResponseErrorConfig<Error>, { data?: CreateUsersWithListInputMutationRequest }, TContext>
47+
> & { client?: QueryClient }
48+
client?: Partial<RequestConfig<CreateUsersWithListInputMutationRequest>> & { client?: typeof fetch }
49+
} = {},
50+
) {
51+
const { mutation = {}, client: config = {} } = options ?? {}
52+
const { client: queryClient, ...mutationOptions } = mutation
53+
const mutationKey = mutationOptions.mutationKey ?? createUsersWithListInputMutationKey()
54+
55+
return useMutation<CreateUsersWithListInputMutationResponse, ResponseErrorConfig<Error>, { data?: CreateUsersWithListInputMutationRequest }, TContext>(
56+
() => ({
57+
mutationFn: async ({ data }) => {
58+
return createUsersWithListInput(data, config)
59+
},
60+
mutationKey,
61+
...mutationOptions,
62+
}),
63+
queryClient ? () => queryClient : undefined,
64+
)
65+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/**
2+
* Generated by Kubb (https://kubb.dev/).
3+
* Do not edit manually.
4+
*/
5+
6+
import fetch from '@kubb/plugin-client/clients/axios'
7+
import type { DeleteOrderMutationResponse, DeleteOrderPathParams, DeleteOrder400, DeleteOrder404 } from '../models/DeleteOrder.ts'
8+
import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/axios'
9+
import type { UseMutationOptions, QueryClient } from '@tanstack/solid-query'
10+
import { useMutation } from '@tanstack/solid-query'
11+
12+
export const deleteOrderMutationKey = () => [{ url: '/store/order/:orderId' }] as const
13+
14+
export type DeleteOrderMutationKey = ReturnType<typeof deleteOrderMutationKey>
15+
16+
/**
17+
* @description For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
18+
* @summary Delete purchase order by ID
19+
* {@link /store/order/:orderId}
20+
*/
21+
export async function deleteOrder(orderId: DeleteOrderPathParams['orderId'], config: Partial<RequestConfig> & { client?: typeof fetch } = {}) {
22+
const { client: request = fetch, ...requestConfig } = config
23+
24+
const res = await request<DeleteOrderMutationResponse, ResponseErrorConfig<DeleteOrder400 | DeleteOrder404>, unknown>({
25+
method: 'DELETE',
26+
url: `/store/order/${orderId}`,
27+
...requestConfig,
28+
})
29+
return res.data
30+
}
31+
32+
/**
33+
* @description For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
34+
* @summary Delete purchase order by ID
35+
* {@link /store/order/:orderId}
36+
*/
37+
export function useDeleteOrder<TContext>(
38+
options: {
39+
mutation?: ReturnType<
40+
UseMutationOptions<
41+
DeleteOrderMutationResponse,
42+
ResponseErrorConfig<DeleteOrder400 | DeleteOrder404>,
43+
{ orderId: DeleteOrderPathParams['orderId'] },
44+
TContext
45+
>
46+
> & { client?: QueryClient }
47+
client?: Partial<RequestConfig> & { client?: typeof fetch }
48+
} = {},
49+
) {
50+
const { mutation = {}, client: config = {} } = options ?? {}
51+
const { client: queryClient, ...mutationOptions } = mutation
52+
const mutationKey = mutationOptions.mutationKey ?? deleteOrderMutationKey()
53+
54+
return useMutation<
55+
DeleteOrderMutationResponse,
56+
ResponseErrorConfig<DeleteOrder400 | DeleteOrder404>,
57+
{ orderId: DeleteOrderPathParams['orderId'] },
58+
TContext
59+
>(
60+
() => ({
61+
mutationFn: async ({ orderId }) => {
62+
return deleteOrder(orderId, config)
63+
},
64+
mutationKey,
65+
...mutationOptions,
66+
}),
67+
queryClient ? () => queryClient : undefined,
68+
)
69+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* Generated by Kubb (https://kubb.dev/).
3+
* Do not edit manually.
4+
*/
5+
6+
import fetch from '@kubb/plugin-client/clients/axios'
7+
import type { DeletePetMutationResponse, DeletePetPathParams, DeletePetHeaderParams, DeletePet400 } from '../models/DeletePet.ts'
8+
import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/axios'
9+
import type { UseMutationOptions, QueryClient } from '@tanstack/solid-query'
10+
import { useMutation } from '@tanstack/solid-query'
11+
12+
export const deletePetMutationKey = () => [{ url: '/pet/:petId' }] as const
13+
14+
export type DeletePetMutationKey = ReturnType<typeof deletePetMutationKey>
15+
16+
/**
17+
* @description delete a pet
18+
* @summary Deletes a pet
19+
* {@link /pet/:petId}
20+
*/
21+
export async function deletePet(
22+
petId: DeletePetPathParams['petId'],
23+
headers?: DeletePetHeaderParams,
24+
config: Partial<RequestConfig> & { client?: typeof fetch } = {},
25+
) {
26+
const { client: request = fetch, ...requestConfig } = config
27+
28+
const res = await request<DeletePetMutationResponse, ResponseErrorConfig<DeletePet400>, unknown>({
29+
method: 'DELETE',
30+
url: `/pet/${petId}`,
31+
...requestConfig,
32+
headers: { ...headers, ...requestConfig.headers },
33+
})
34+
return res.data
35+
}
36+
37+
/**
38+
* @description delete a pet
39+
* @summary Deletes a pet
40+
* {@link /pet/:petId}
41+
*/
42+
export function useDeletePet<TContext>(
43+
options: {
44+
mutation?: ReturnType<
45+
UseMutationOptions<
46+
DeletePetMutationResponse,
47+
ResponseErrorConfig<DeletePet400>,
48+
{ petId: DeletePetPathParams['petId']; headers?: DeletePetHeaderParams },
49+
TContext
50+
>
51+
> & { client?: QueryClient }
52+
client?: Partial<RequestConfig> & { client?: typeof fetch }
53+
} = {},
54+
) {
55+
const { mutation = {}, client: config = {} } = options ?? {}
56+
const { client: queryClient, ...mutationOptions } = mutation
57+
const mutationKey = mutationOptions.mutationKey ?? deletePetMutationKey()
58+
59+
return useMutation<
60+
DeletePetMutationResponse,
61+
ResponseErrorConfig<DeletePet400>,
62+
{ petId: DeletePetPathParams['petId']; headers?: DeletePetHeaderParams },
63+
TContext
64+
>(
65+
() => ({
66+
mutationFn: async ({ petId, headers }) => {
67+
return deletePet(petId, headers, config)
68+
},
69+
mutationKey,
70+
...mutationOptions,
71+
}),
72+
queryClient ? () => queryClient : undefined,
73+
)
74+
}

0 commit comments

Comments
 (0)