/** * Branch heads — mutable pointers into the commit chain * @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 { buildListSelectionArgs } from '../selection'; import type { ListSelectionConfig } from '../selection'; import { refKeys } from '../query-keys'; import type { RefSelect, RefWithRelations, RefFilter, RefOrderBy } from '../../orm/input-types'; import type { FindManyArgs, InferSelectResult, ConnectionResult, HookStrictSelect, } from '../../orm/select-types'; export type { RefSelect, RefWithRelations, RefFilter, RefOrderBy } from '../../orm/input-types'; /** Query key factory - re-exported from query-keys.ts */ export const refsQueryKey = refKeys.list; /** * Branch heads — mutable pointers into the commit chain * * @example * ```tsx * const { data, isLoading } = useRefsQuery({ * selection: { * fields: { id: true, name: true }, * where: { name: { equalTo: "example" } }, * orderBy: ['CREATED_AT_DESC'], * first: 10, * }, * }); * ``` */ export function useRefsQuery< S extends RefSelect, TData = { refs: ConnectionResult>; }, >( params: { selection: { fields: S; } & Omit, 'fields'> & HookStrictSelect, RefSelect>; } & Omit< UseQueryOptions< { refs: ConnectionResult>; }, Error, TData >, 'queryKey' | 'queryFn' > ): UseQueryResult; export function useRefsQuery( params: { selection: ListSelectionConfig; } & Omit, 'queryKey' | 'queryFn'> ) { const args = buildListSelectionArgs(params.selection); const { selection: _selection, ...queryOptions } = params ?? {}; void _selection; return useQuery({ queryKey: refKeys.list(args), queryFn: () => getClient().ref.findMany(args).unwrap(), ...queryOptions, }); } /** * Branch heads — mutable pointers into the commit chain * * @example * ```ts * const data = await fetchRefsQuery({ * selection: { * fields: { id: true }, * first: 10, * }, * }); * ``` */ export async function fetchRefsQuery(params: { selection: { fields: S; } & Omit, 'fields'> & HookStrictSelect, RefSelect>; }): Promise<{ refs: ConnectionResult>; }>; export async function fetchRefsQuery(params: { selection: ListSelectionConfig; }) { const args = buildListSelectionArgs(params.selection); return getClient().ref.findMany(args).unwrap(); } /** * Branch heads — mutable pointers into the commit chain * * @example * ```ts * await prefetchRefsQuery(queryClient, { selection: { fields: { id: true }, first: 10 } }); * ``` */ export async function prefetchRefsQuery( queryClient: QueryClient, params: { selection: { fields: S; } & Omit, 'fields'> & HookStrictSelect, RefSelect>; } ): Promise; export async function prefetchRefsQuery( queryClient: QueryClient, params: { selection: ListSelectionConfig; } ): Promise { const args = buildListSelectionArgs(params.selection); await queryClient.prefetchQuery({ queryKey: refKeys.list(args), queryFn: () => getClient().ref.findMany(args).unwrap(), }); }