Files
Dani Akash 290ee91a8b Add 'packages/browseros-agent/' from commit '90bd4be3008285bf3825aad3702aff98f872671a'
git-subtree-dir: packages/browseros-agent
git-subtree-mainline: 8f148d0918
git-subtree-split: 90bd4be300
2026-03-13 21:22:09 +05:30

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 ?? {}),
})
}