/** * Content-addressed Merkle tree objects keyed by UUID v5 hash of data + children * @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 { infraObjectKeys } from '../query-keys'; import type { InfraObjectSelect, InfraObjectWithRelations, InfraObjectFilter, InfraObjectOrderBy, } from '../../orm/input-types'; import type { FindManyArgs, InferSelectResult, ConnectionResult, HookStrictSelect, } from '../../orm/select-types'; export type { InfraObjectSelect, InfraObjectWithRelations, InfraObjectFilter, InfraObjectOrderBy, } from '../../orm/input-types'; /** Query key factory - re-exported from query-keys.ts */ export const infraObjectsQueryKey = infraObjectKeys.list; /** * Content-addressed Merkle tree objects keyed by UUID v5 hash of data + children * * @example * ```tsx * const { data, isLoading } = useInfraObjectsQuery({ * selection: { * fields: { id: true, name: true }, * where: { name: { equalTo: "example" } }, * orderBy: ['CREATED_AT_DESC'], * first: 10, * }, * }); * ``` */ export function useInfraObjectsQuery< S extends InfraObjectSelect, TData = { infraObjects: ConnectionResult>; }, >( params: { selection: { fields: S; } & Omit, 'fields'> & HookStrictSelect, InfraObjectSelect>; } & Omit< UseQueryOptions< { infraObjects: ConnectionResult>; }, Error, TData >, 'queryKey' | 'queryFn' > ): UseQueryResult; export function useInfraObjectsQuery( params: { selection: ListSelectionConfig; } & Omit, 'queryKey' | 'queryFn'> ) { const args = buildListSelectionArgs( params.selection ); const { selection: _selection, ...queryOptions } = params ?? {}; void _selection; return useQuery({ queryKey: infraObjectKeys.list(args), queryFn: () => getClient().infraObject.findMany(args).unwrap(), ...queryOptions, }); } /** * Content-addressed Merkle tree objects keyed by UUID v5 hash of data + children * * @example * ```ts * const data = await fetchInfraObjectsQuery({ * selection: { * fields: { id: true }, * first: 10, * }, * }); * ``` */ export async function fetchInfraObjectsQuery(params: { selection: { fields: S; } & Omit, 'fields'> & HookStrictSelect, InfraObjectSelect>; }): Promise<{ infraObjects: ConnectionResult>; }>; export async function fetchInfraObjectsQuery(params: { selection: ListSelectionConfig; }) { const args = buildListSelectionArgs( params.selection ); return getClient().infraObject.findMany(args).unwrap(); } /** * Content-addressed Merkle tree objects keyed by UUID v5 hash of data + children * * @example * ```ts * await prefetchInfraObjectsQuery(queryClient, { selection: { fields: { id: true }, first: 10 } }); * ``` */ export async function prefetchInfraObjectsQuery( queryClient: QueryClient, params: { selection: { fields: S; } & Omit, 'fields'> & HookStrictSelect, InfraObjectSelect>; } ): Promise; export async function prefetchInfraObjectsQuery( queryClient: QueryClient, params: { selection: ListSelectionConfig; } ): Promise { const args = buildListSelectionArgs( params.selection ); await queryClient.prefetchQuery({ queryKey: infraObjectKeys.list(args), queryFn: () => getClient().infraObject.findMany(args).unwrap(), }); }