Created
April 28, 2025 14:38
-
-
Save Zylvian/3426bc6272b29d8a916dcbe8e7595aaf to your computer and use it in GitHub Desktop.
Orval example output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Generated by orval v7.9.0 🍺 | |
* Do not edit manually. | |
* MinimalApi | v1 | |
* OpenAPI spec version: 1.0.0 | |
*/ | |
import { | |
useQuery | |
} from '@tanstack/react-query'; | |
import type { | |
DataTag, | |
DefinedInitialDataOptions, | |
DefinedUseQueryResult, | |
QueryClient, | |
QueryFunction, | |
QueryKey, | |
UndefinedInitialDataOptions, | |
UseQueryOptions, | |
UseQueryResult | |
} from '@tanstack/react-query'; | |
import type { | |
WeatherForecast | |
} from '.././model'; | |
export type getWeatherForecastResponse200 = { | |
data: WeatherForecast[] | |
status: 200 | |
} | |
export type getWeatherForecastResponseComposite = getWeatherForecastResponse200; | |
export type getWeatherForecastResponse = getWeatherForecastResponseComposite & { | |
headers: Headers; | |
} | |
export const getGetWeatherForecastUrl = () => { | |
return `http://localhost:5188/weatherforecast` | |
} | |
export const getWeatherForecast = async ( options?: RequestInit): Promise<getWeatherForecastResponse> => { | |
const res = await fetch(getGetWeatherForecastUrl(), | |
{ | |
...options, | |
method: 'GET' | |
} | |
) | |
const body = [204, 205, 304].includes(res.status) ? null : await res.text() | |
const data: getWeatherForecastResponse['data'] = body ? JSON.parse(body) : {} | |
return { data, status: res.status, headers: res.headers } as getWeatherForecastResponse | |
} | |
export const getGetWeatherForecastQueryKey = () => { | |
return [`http://localhost:5188/weatherforecast`] as const; | |
} | |
export const getGetWeatherForecastQueryOptions = <TData = Awaited<ReturnType<typeof getWeatherForecast>>, TError = unknown>( options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getWeatherForecast>>, TError, TData>>, fetch?: RequestInit} | |
) => { | |
const {query: queryOptions, fetch: fetchOptions} = options ?? {}; | |
const queryKey = queryOptions?.queryKey ?? getGetWeatherForecastQueryKey(); | |
const queryFn: QueryFunction<Awaited<ReturnType<typeof getWeatherForecast>>> = ({ signal }) => getWeatherForecast({ signal, ...fetchOptions }); | |
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getWeatherForecast>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> } | |
} | |
export type GetWeatherForecastQueryResult = NonNullable<Awaited<ReturnType<typeof getWeatherForecast>>> | |
export type GetWeatherForecastQueryError = unknown | |
export function useGetWeatherForecast<TData = Awaited<ReturnType<typeof getWeatherForecast>>, TError = unknown>( | |
options: { query:Partial<UseQueryOptions<Awaited<ReturnType<typeof getWeatherForecast>>, TError, TData>> & Pick< | |
DefinedInitialDataOptions< | |
Awaited<ReturnType<typeof getWeatherForecast>>, | |
TError, | |
Awaited<ReturnType<typeof getWeatherForecast>> | |
> , 'initialData' | |
>, fetch?: RequestInit} | |
, queryClient?: QueryClient | |
): DefinedUseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> } | |
export function useGetWeatherForecast<TData = Awaited<ReturnType<typeof getWeatherForecast>>, TError = unknown>( | |
options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getWeatherForecast>>, TError, TData>> & Pick< | |
UndefinedInitialDataOptions< | |
Awaited<ReturnType<typeof getWeatherForecast>>, | |
TError, | |
Awaited<ReturnType<typeof getWeatherForecast>> | |
> , 'initialData' | |
>, fetch?: RequestInit} | |
, queryClient?: QueryClient | |
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> } | |
export function useGetWeatherForecast<TData = Awaited<ReturnType<typeof getWeatherForecast>>, TError = unknown>( | |
options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getWeatherForecast>>, TError, TData>>, fetch?: RequestInit} | |
, queryClient?: QueryClient | |
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> } | |
export function useGetWeatherForecast<TData = Awaited<ReturnType<typeof getWeatherForecast>>, TError = unknown>( | |
options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getWeatherForecast>>, TError, TData>>, fetch?: RequestInit} | |
, queryClient?: QueryClient | |
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> } { | |
const queryOptions = getGetWeatherForecastQueryOptions(options) | |
const query = useQuery(queryOptions , queryClient) as UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }; | |
query.queryKey = queryOptions.queryKey ; | |
return query; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment