/** * Custom query hook for currentUser * @generated by @constructive-io/graphql-codegen * DO NOT EDIT - changes will be overwritten */ import { useQuery } from '@tanstack/react-query'; import type { UseQueryOptions, UseQueryResult, QueryClient } from '@tanstack/react-query'; import { getClient } from '../client'; import { buildSelectionArgs } from '../selection'; import type { SelectionConfig } from '../selection'; import { customQueryKeys } from '../query-keys'; import type { UserSelect, User } from '../../orm/input-types'; import type { InferSelectResult, HookStrictSelect } from '../../orm/select-types'; export type { UserSelect } from '../../orm/input-types'; /** Query key factory - re-exported from query-keys.ts */ export const currentUserQueryKey = customQueryKeys.currentUser; /** * Query hook for currentUser * * @example * ```tsx * const { data, isLoading } = useCurrentUserQuery({ selection: { fields: { id: true } } }); * * if (data?.currentUser) { * console.log(data.currentUser); * } * ``` */ export function useCurrentUserQuery< S extends UserSelect, TData = { currentUser: InferSelectResult | null; }, >( params: { selection: { fields: S & UserSelect; } & HookStrictSelect, UserSelect>; } & Omit< UseQueryOptions< { currentUser: InferSelectResult | null; }, Error, TData >, 'queryKey' | 'queryFn' > ): UseQueryResult; export function useCurrentUserQuery( params: { selection: SelectionConfig; } & Omit, 'queryKey' | 'queryFn'> ) { const args = buildSelectionArgs(params.selection); const { selection: _selection, ...queryOptions } = params ?? {}; void _selection; return useQuery({ queryKey: currentUserQueryKey(), queryFn: () => getClient() .query.currentUser({ select: args.select, }) .unwrap(), ...queryOptions, }); } /** * Fetch currentUser without React hooks * * @example * ```ts * const data = await fetchCurrentUserQuery({ selection: { fields: { id: true } } }); * ``` */ export async function fetchCurrentUserQuery(params: { selection: { fields: S & UserSelect; } & HookStrictSelect, UserSelect>; }): Promise<{ currentUser: InferSelectResult | null; }>; export async function fetchCurrentUserQuery(params: { selection: SelectionConfig }) { const args = buildSelectionArgs(params.selection); return getClient() .query.currentUser({ select: args.select, }) .unwrap(); } /** * Prefetch currentUser for SSR or cache warming * * @example * ```ts * await prefetchCurrentUserQuery(queryClient, { selection: { fields: { id: true } } }); * ``` */ export async function prefetchCurrentUserQuery( queryClient: QueryClient, params: { selection: { fields: S & UserSelect; } & HookStrictSelect, UserSelect>; } ): Promise; export async function prefetchCurrentUserQuery( queryClient: QueryClient, params: { selection: SelectionConfig; } ): Promise { const args = buildSelectionArgs(params.selection); await queryClient.prefetchQuery({ queryKey: currentUserQueryKey(), queryFn: () => getClient() .query.currentUser({ select: args.select, }) .unwrap(), }); }