/** * List query hook for Table * @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 { tableKeys } from '../query-keys'; import type { TableSelect, TableWithRelations, TableFilter, TableOrderBy, } from '../../orm/input-types'; import type { FindManyArgs, InferSelectResult, ConnectionResult, HookStrictSelect, } from '../../orm/select-types'; export type { TableSelect, TableWithRelations, TableFilter, TableOrderBy, } from '../../orm/input-types'; /** Query key factory - re-exported from query-keys.ts */ export const tablesQueryKey = tableKeys.list; /** * Query hook for fetching Table list * * @example * ```tsx * const { data, isLoading } = useTablesQuery({ * selection: { * fields: { id: true, name: true }, * where: { name: { equalTo: "example" } }, * orderBy: ['CREATED_AT_DESC'], * first: 10, * }, * }); * ``` */ export function useTablesQuery< S extends TableSelect, TData = { tables: ConnectionResult>; }, >( params: { selection: { fields: S; } & Omit, 'fields'> & HookStrictSelect, TableSelect>; } & Omit< UseQueryOptions< { tables: ConnectionResult>; }, Error, TData >, 'queryKey' | 'queryFn' > ): UseQueryResult; export function useTablesQuery( params: { selection: ListSelectionConfig; } & Omit, 'queryKey' | 'queryFn'> ) { const args = buildListSelectionArgs(params.selection); const { selection: _selection, ...queryOptions } = params ?? {}; void _selection; return useQuery({ queryKey: tableKeys.list(args), queryFn: () => getClient().table.findMany(args).unwrap(), ...queryOptions, }); } /** * Fetch Table list without React hooks * * @example * ```ts * const data = await fetchTablesQuery({ * selection: { * fields: { id: true }, * first: 10, * }, * }); * ``` */ export async function fetchTablesQuery(params: { selection: { fields: S; } & Omit, 'fields'> & HookStrictSelect, TableSelect>; }): Promise<{ tables: ConnectionResult>; }>; export async function fetchTablesQuery(params: { selection: ListSelectionConfig; }) { const args = buildListSelectionArgs(params.selection); return getClient().table.findMany(args).unwrap(); } /** * Prefetch Table list for SSR or cache warming * * @example * ```ts * await prefetchTablesQuery(queryClient, { selection: { fields: { id: true }, first: 10 } }); * ``` */ export async function prefetchTablesQuery( queryClient: QueryClient, params: { selection: { fields: S; } & Omit, 'fields'> & HookStrictSelect, TableSelect>; } ): Promise; export async function prefetchTablesQuery( queryClient: QueryClient, params: { selection: ListSelectionConfig; } ): Promise { const args = buildListSelectionArgs(params.selection); await queryClient.prefetchQuery({ queryKey: tableKeys.list(args), queryFn: () => getClient().table.findMany(args).unwrap(), }); }