UNPKG

@kubb/plugin-react-query

Version:

Generator react-query hooks

92 lines (82 loc) 3.54 kB
/** * Generated by Kubb (https://kubb.dev/). * Do not edit manually. */ import client from '@kubb/plugin-client/clients/axios' import type { RequestConfig, ResponseErrorConfig } from '@kubb/plugin-client/clients/axios' import type { QueryKey, QueryClient, QueryObserverOptions, UseQueryResult } from 'custom-query' import { queryOptions, useQuery } from 'custom-query' export const updatePetWithFormQueryKey = ( petId: UpdatePetWithFormPathParams['petId'], data?: UpdatePetWithFormMutationRequest, params?: UpdatePetWithFormQueryParams, ) => [{ url: '/pet/:pet_id', params: { pet_id: pet_id } }, ...(params ? [params] : []), ...(data ? [data] : [])] as const export type UpdatePetWithFormQueryKey = ReturnType<typeof updatePetWithFormQueryKey> /** * @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 client } = {}, ) { const { client: request = client, ...requestConfig } = config const res = await request<UpdatePetWithFormMutationResponse, ResponseErrorConfig<UpdatePetWithForm405>, UpdatePetWithFormMutationRequest>({ method: 'POST', url: `/pet/${pet_id}`, params, data: updatePetWithFormMutationRequest.parse(data), ...requestConfig, }) return updatePetWithFormMutationResponse.parse(res.data) } export function updatePetWithFormQueryOptions( petId: UpdatePetWithFormPathParams['petId'], data?: UpdatePetWithFormMutationRequest, params?: UpdatePetWithFormQueryParams, config: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> & { client?: typeof client } = {}, ) { const queryKey = updatePetWithFormQueryKey(petId, data, params) return queryOptions<UpdatePetWithFormMutationResponse, ResponseErrorConfig<UpdatePetWithForm405>, UpdatePetWithFormMutationResponse, typeof queryKey>({ enabled: !!petId, queryKey, queryFn: async ({ signal }) => { config.signal = signal return updatePetWithForm(petId, data, params, config) }, }) } /** * @summary Updates a pet in the store with form data * {@link /pet/:pet_id} */ export function useUpdatePetWithForm< TData = UpdatePetWithFormMutationResponse, TQueryData = UpdatePetWithFormMutationResponse, TQueryKey extends QueryKey = UpdatePetWithFormQueryKey, >( petId: UpdatePetWithFormPathParams['petId'], data?: UpdatePetWithFormMutationRequest, params?: UpdatePetWithFormQueryParams, options: { query?: Partial<QueryObserverOptions<UpdatePetWithFormMutationResponse, ResponseErrorConfig<UpdatePetWithForm405>, TData, TQueryData, TQueryKey>> & { client?: QueryClient } client?: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> & { client?: typeof client } } = {}, ) { const { query: { client: queryClient, ...queryOptions } = {}, client: config = {} } = options ?? {} const queryKey = queryOptions?.queryKey ?? updatePetWithFormQueryKey(petId, data, params) const query = useQuery( { ...(updatePetWithFormQueryOptions(petId, data, params, config) as unknown as QueryObserverOptions), queryKey, ...(queryOptions as unknown as Omit<QueryObserverOptions, 'queryKey'>), }, queryClient, ) as UseQueryResult<TData, ResponseErrorConfig<UpdatePetWithForm405>> & { queryKey: TQueryKey } query.queryKey = queryKey as TQueryKey return query }