UNPKG

@kubb/plugin-react-query

Version:

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

98 lines (88 loc) 3.66 kB
/** * Generated by Kubb (https://kubb.dev/). * Do not edit manually. */ import fetch from 'axios' import type { UseMutationOptions, UseMutationResult, QueryClient } from '@tanstack/react-query' import type { RequestConfig, ResponseErrorConfig } from 'axios' import { mutationOptions, useMutation } from '@tanstack/react-query' export const updatePetWithFormMutationKey = () => [{ url: '/pet/:pet_id' }] as const export type UpdatePetWithFormMutationKey = ReturnType<typeof updatePetWithFormMutationKey> /** * @summary Updates a pet in the store with form data * {@link /pet/:pet_id} */ export async function updatePetWithForm( 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/${pet_id}`, params, data: requestData, ...requestConfig, }) return updatePetWithFormMutationResponse.parse(res.data) } export function updatePetWithFormMutationOptions(config: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> & { client?: typeof fetch } = {}) { const mutationKey = updatePetWithFormMutationKey() return mutationOptions< UpdatePetWithFormMutationResponse, ResponseErrorConfig<UpdatePetWithForm405>, { petId: UpdatePetWithFormPathParams['petId']; data?: UpdatePetWithFormMutationRequest; params?: UpdatePetWithFormQueryParams }, typeof mutationKey >({ mutationKey, mutationFn: async ({ petId, data, params }) => { return updatePetWithForm(petId, data, params, config) }, }) } /** * @summary Updates a pet in the store with form data * {@link /pet/:pet_id} */ export function useUpdatePetWithForm<TContext>( options: { mutation?: 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() const baseOptions = updatePetWithFormMutationOptions(config) as UseMutationOptions< UpdatePetWithFormMutationResponse, ResponseErrorConfig<UpdatePetWithForm405>, { petId: UpdatePetWithFormPathParams['petId']; data?: UpdatePetWithFormMutationRequest; params?: UpdatePetWithFormQueryParams }, TContext > return useMutation< UpdatePetWithFormMutationResponse, ResponseErrorConfig<UpdatePetWithForm405>, { petId: UpdatePetWithFormPathParams['petId']; data?: UpdatePetWithFormMutationRequest; params?: UpdatePetWithFormQueryParams }, TContext >( { ...baseOptions, mutationKey, ...mutationOptions, }, queryClient, ) as UseMutationResult< UpdatePetWithFormMutationResponse, ResponseErrorConfig<UpdatePetWithForm405>, { petId: UpdatePetWithFormPathParams['petId']; data?: UpdatePetWithFormMutationRequest; params?: UpdatePetWithFormQueryParams }, TContext > }