mirror of
https://github.com/browseros-ai/BrowserOS.git
synced 2026-05-13 23:53:25 +00:00
git-subtree-dir: packages/browseros-agent git-subtree-mainline:8f148d0918git-subtree-split:90bd4be300
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
import {
|
|
type InfiniteData,
|
|
type UseInfiniteQueryOptions,
|
|
type UseInfiniteQueryResult,
|
|
useInfiniteQuery,
|
|
} from '@tanstack/react-query'
|
|
import type { TypedDocumentString } from '@/generated/graphql/graphql'
|
|
import { execute } from './execute'
|
|
import { getQueryKeyFromDocument } from './getQueryKeyFromDocument'
|
|
|
|
/**
|
|
* @public
|
|
*/
|
|
export const useGraphqlInfiniteQuery = <
|
|
TQueryFnData,
|
|
// biome-ignore lint/suspicious/noExplicitAny: TODO(dani) type GraphQL variables properly
|
|
TVariables extends Record<string, any> | undefined = undefined,
|
|
TPageParam extends string | undefined | number = undefined,
|
|
>(
|
|
query: TypedDocumentString<TQueryFnData, TVariables>,
|
|
getVariables: (pageParam: TPageParam) => TVariables,
|
|
options: Omit<
|
|
UseInfiniteQueryOptions<
|
|
TQueryFnData, // TQueryFnData
|
|
Error, // TError
|
|
InfiniteData<TQueryFnData, TPageParam> // TData
|
|
>,
|
|
'queryKey' | 'queryFn'
|
|
> & {
|
|
/** Required by React Query v5 */
|
|
initialPageParam: TPageParam
|
|
},
|
|
): UseInfiniteQueryResult<InfiniteData<TQueryFnData, TPageParam>, Error> => {
|
|
const queryKey = [getQueryKeyFromDocument(query)] as const
|
|
|
|
return useInfiniteQuery<
|
|
TQueryFnData, // TQueryFnData
|
|
Error, // TError
|
|
InfiniteData<TQueryFnData, TPageParam> // TData (pages + pageParams)
|
|
>({
|
|
queryKey,
|
|
queryFn: async ({ pageParam }) =>
|
|
execute<TQueryFnData, TVariables>(
|
|
query,
|
|
getVariables(pageParam as TPageParam),
|
|
),
|
|
...options,
|
|
})
|
|
}
|