/** * Site-owned page content — merkle-versioned head over the infra store; never a routing surface * @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 { pageKeys } from '../query-keys'; import type { PageSelect, PageWithRelations, PageFilter, PageOrderBy } from '../../orm/input-types'; import type { FindManyArgs, InferSelectResult, ConnectionResult, HookStrictSelect, } from '../../orm/select-types'; export type { PageSelect, PageWithRelations, PageFilter, PageOrderBy } from '../../orm/input-types'; /** Query key factory - re-exported from query-keys.ts */ export const pagesQueryKey = pageKeys.list; /** * Site-owned page content — merkle-versioned head over the infra store; never a routing surface * * @example * ```tsx * const { data, isLoading } = usePagesQuery({ * selection: { * fields: { id: true, name: true }, * where: { name: { equalTo: "example" } }, * orderBy: ['CREATED_AT_DESC'], * first: 10, * }, * }); * ``` */ export function usePagesQuery< S extends PageSelect, TData = { pages: ConnectionResult>; }, >( params: { selection: { fields: S; } & Omit, 'fields'> & HookStrictSelect, PageSelect>; } & Omit< UseQueryOptions< { pages: ConnectionResult>; }, Error, TData >, 'queryKey' | 'queryFn' > ): UseQueryResult; export function usePagesQuery( params: { selection: ListSelectionConfig; } & Omit, 'queryKey' | 'queryFn'> ) { const args = buildListSelectionArgs(params.selection); const { selection: _selection, ...queryOptions } = params ?? {}; void _selection; return useQuery({ queryKey: pageKeys.list(args), queryFn: () => getClient().page.findMany(args).unwrap(), ...queryOptions, }); } /** * Site-owned page content — merkle-versioned head over the infra store; never a routing surface * * @example * ```ts * const data = await fetchPagesQuery({ * selection: { * fields: { id: true }, * first: 10, * }, * }); * ``` */ export async function fetchPagesQuery(params: { selection: { fields: S; } & Omit, 'fields'> & HookStrictSelect, PageSelect>; }): Promise<{ pages: ConnectionResult>; }>; export async function fetchPagesQuery(params: { selection: ListSelectionConfig; }) { const args = buildListSelectionArgs(params.selection); return getClient().page.findMany(args).unwrap(); } /** * Site-owned page content — merkle-versioned head over the infra store; never a routing surface * * @example * ```ts * await prefetchPagesQuery(queryClient, { selection: { fields: { id: true }, first: 10 } }); * ``` */ export async function prefetchPagesQuery( queryClient: QueryClient, params: { selection: { fields: S; } & Omit, 'fields'> & HookStrictSelect, PageSelect>; } ): Promise; export async function prefetchPagesQuery( queryClient: QueryClient, params: { selection: ListSelectionConfig; } ): Promise { const args = buildListSelectionArgs(params.selection); await queryClient.prefetchQuery({ queryKey: pageKeys.list(args), queryFn: () => getClient().page.findMany(args).unwrap(), }); }