UNPKG

@kubb/plugin-solid-query

Version:

Solid Query hooks generator plugin for Kubb, creating type-safe API client hooks from OpenAPI specifications for Solid.js applications.

75 lines (67 loc) 2.67 kB
/** * Generated by Kubb (https://kubb.dev/). * Do not edit manually. */ import fetch from '@kubb/plugin-client/clients/axios' import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/axios' import type { UseMutationOptions, QueryClient } from '@tanstack/solid-query' import { useMutation } from '@tanstack/solid-query' export const updatePetWithFormMutationKey = () => [{ url: '/pet/:petId' }] as const export type UpdatePetWithFormMutationKey = ReturnType<typeof updatePetWithFormMutationKey> /** * @summary Updates a pet in the store with form data * {@link /pet/:petId} */ export async function updatePetWithForm( { petId }: { petId: UpdatePetWithFormPathParams['petId'] }, data?: UpdatePetWithFormMutationRequest, params?: UpdatePetWithFormQueryParams, config: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> & { client?: typeof fetch } = {}, ) { const { client: request = fetch, ...requestConfig } = config const requestData = updatePetWithFormMutationRequest.parse(data) const res = await request<UpdatePetWithFormMutationResponse, ResponseErrorConfig<UpdatePetWithForm405>, UpdatePetWithFormMutationRequest>({ method: 'POST', url: `/pet/${petId}`, params, data: requestData, ...requestConfig, }) return updatePetWithFormMutationResponse.parse(res.data) } /** * @summary Updates a pet in the store with form data * {@link /pet/:petId} */ export function useUpdatePetWithForm<TContext>( options: { mutation?: ReturnType< UseMutationOptions< UpdatePetWithFormMutationResponse, ResponseErrorConfig<UpdatePetWithForm405>, { petId: UpdatePetWithFormPathParams['petId']; data?: UpdatePetWithFormMutationRequest; params?: UpdatePetWithFormQueryParams }, TContext > > & { client?: QueryClient } client?: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> & { client?: typeof fetch } } = {}, ) { const { mutation = {}, client: config = {} } = options ?? {} const { client: queryClient, ...mutationOptions } = mutation const mutationKey = mutationOptions.mutationKey ?? updatePetWithFormMutationKey() return useMutation< UpdatePetWithFormMutationResponse, ResponseErrorConfig<UpdatePetWithForm405>, { petId: UpdatePetWithFormPathParams['petId']; data?: UpdatePetWithFormMutationRequest; params?: UpdatePetWithFormQueryParams }, TContext >( () => ({ mutationFn: async ({ petId, data, params }) => { return updatePetWithForm({ petId }, data, params, config) }, mutationKey, ...mutationOptions, }), queryClient ? () => queryClient : undefined, ) }