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
26 lines
877 B
TypeScript
26 lines
877 B
TypeScript
import { type UseQueryOptions, useQuery } from '@tanstack/react-query'
|
|
import type { TypedDocumentString } from '@/generated/graphql/graphql'
|
|
import { execute } from './execute'
|
|
import { getQueryKeyFromDocument } from './getQueryKeyFromDocument'
|
|
|
|
/**
|
|
* @public
|
|
*/
|
|
export const useGraphqlQuery = <
|
|
TResult,
|
|
// biome-ignore lint/suspicious/noExplicitAny: TODO(dani) type GraphQL variables properly
|
|
TVariables extends Record<string, any> | undefined = undefined,
|
|
>(
|
|
query: TypedDocumentString<TResult, TVariables>,
|
|
variables?: TVariables,
|
|
options?: Omit<UseQueryOptions<TResult, Error>, 'queryKey' | 'queryFn'>,
|
|
) => {
|
|
const queryKey = getQueryKeyFromDocument(query)
|
|
|
|
return useQuery<TResult, Error>({
|
|
queryKey: variables ? [queryKey, variables] : [queryKey],
|
|
queryFn: () => execute<TResult, TVariables>(query, variables),
|
|
...(options ?? {}),
|
|
})
|
|
}
|