import { type BaseGeneratedSchema, type GQtyClient, type RetryOptions } from 'gqty'; import { coreHelpers, sortBy, uniqBy, type LegacyFetchPolicy } from '../common'; import type { ReactClientOptionsWithDefaults } from '../utils'; export type PaginatedQueryFetchPolicy = Extract; export interface UsePaginatedQueryMergeParams { data: { existing: TData | undefined; incoming: TData; }; uniqBy: typeof uniqBy; sortBy: typeof sortBy; } export interface UsePaginatedQueryOptions { /** * Initial arguments used on first request */ initialArgs: TArgs; /** * Custom merge function */ merge?: (params: UsePaginatedQueryMergeParams) => TData | undefined | void; /** * Fetch Policy behavior * * If using `cache-and-network` and `merge`, we recomend using the `uniqBy` * helper included inside the `merge` parameters. */ fetchPolicy?: PaginatedQueryFetchPolicy; operationName?: string; retry?: RetryOptions; /** * Skip initial query call * * @default false */ skip?: boolean; /** * Activate suspense on first call */ suspense?: boolean; } export interface UsePaginatedQueryData { /** * Query Data */ data: TData | undefined; /** * Current arguments used in the query */ args: TArgs; /** * Network fetch is loading */ isLoading: boolean; /** * Main function to be used * * If new args are not specified, the previous or initial args are used * * In the second parameter you can override the `"fetchPolicy"`, for example * you can set it to `"network-only"` to do a refetch. */ fetchMore: ( /** * Optional new args. It can receive a function that receives the previous * data/args and returns the new args, or the new args directly * * If not specified or `undefined`, the previous or initial args are used. */ newArgs?: ((data: FetchMoreCallbackArgs) => TArgs) | TArgs | undefined, /** * Override hook fetchPolicy */ fetchPolicy?: PaginatedQueryFetchPolicy) => Promise | TData; } export interface FetchMoreCallbackArgs { existingData: TData | undefined; existingArgs: TArgs; } export interface UsePaginatedQuery { | string | number | null>(fn: (query: TSchema['query'], args: TArgs, helpers: typeof coreHelpers) => TData, options: UsePaginatedQueryOptions): UsePaginatedQueryData; } export declare const createUsePaginatedQuery: ({ createResolver, resolve }: GQtyClient, { defaults: { paginatedQueryFetchPolicy: defaultFetchPolicy, paginatedQuerySuspense: defaultSuspense, }, }: ReactClientOptionsWithDefaults) => UsePaginatedQuery;