/** * Single item query hook for FunctionModule * @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 { functionModuleKeys } from '../query-keys'; import type { FunctionModuleSelect, FunctionModuleWithRelations } from '../../orm/input-types'; import type { InferSelectResult, HookStrictSelect } from '../../orm/select-types'; export type { FunctionModuleSelect, FunctionModuleWithRelations } from '../../orm/input-types'; /** Query key factory - re-exported from query-keys.ts */ export const functionModuleQueryKey = functionModuleKeys.detail; /** * Query hook for fetching a single FunctionModule * * @example * ```tsx * const { data, isLoading } = useFunctionModuleQuery({ * id: 'some-id', * selection: { fields: { id: true, name: true } }, * }); * ``` */ export function useFunctionModuleQuery< S extends FunctionModuleSelect, TData = { functionModule: InferSelectResult | null; }, >( params: { id: string; selection: { fields: S; } & HookStrictSelect, FunctionModuleSelect>; } & Omit< UseQueryOptions< { functionModule: InferSelectResult | null; }, Error, TData >, 'queryKey' | 'queryFn' > ): UseQueryResult; export function useFunctionModuleQuery( params: { id: string; selection: SelectionConfig; } & Omit, 'queryKey' | 'queryFn'> ) { const args = buildSelectionArgs(params.selection); const { selection: _selection, ...queryOptions } = params ?? {}; void _selection; return useQuery({ queryKey: functionModuleKeys.detail(params.id), queryFn: () => getClient() .functionModule.findOne({ id: params.id, select: args.select, }) .unwrap(), ...queryOptions, }); } /** * Fetch a single FunctionModule without React hooks * * @example * ```ts * const data = await fetchFunctionModuleQuery({ * id: 'some-id', * selection: { fields: { id: true } }, * }); * ``` */ export async function fetchFunctionModuleQuery(params: { id: string; selection: { fields: S; } & HookStrictSelect, FunctionModuleSelect>; }): Promise<{ functionModule: InferSelectResult | null; }>; export async function fetchFunctionModuleQuery(params: { id: string; selection: SelectionConfig; }): Promise { const args = buildSelectionArgs(params.selection); return getClient() .functionModule.findOne({ id: params.id, select: args.select, }) .unwrap(); } /** * Prefetch a single FunctionModule for SSR or cache warming * * @example * ```ts * await prefetchFunctionModuleQuery(queryClient, { id: 'some-id', selection: { fields: { id: true } } }); * ``` */ export async function prefetchFunctionModuleQuery( queryClient: QueryClient, params: { id: string; selection: { fields: S; } & HookStrictSelect, FunctionModuleSelect>; } ): Promise; export async function prefetchFunctionModuleQuery( queryClient: QueryClient, params: { id: string; selection: SelectionConfig; } ): Promise { const args = buildSelectionArgs(params.selection); await queryClient.prefetchQuery({ queryKey: functionModuleKeys.detail(params.id), queryFn: () => getClient() .functionModule.findOne({ id: params.id, select: args.select, }) .unwrap(), }); }