import { Disposable, FetchPolicy, IEnvironment, OperationType, ReaderFragment, RenderPolicy, Variables, VariablesOf, } from "relay-runtime"; import { KeyType } from "./helpers"; export type RefetchFn = RefetchFnExact; // NOTE: RefetchFnDynamic returns a refetch function that: // - Expects the /exact/ set of query variables if the provided key type is // /nullable/. // - Or, expects /a subset/ of the query variables if the provided key type is // /non-null/. export type RefetchFnDynamic< TQuery extends OperationType, TKey extends KeyType | null | undefined, TOptions = Options, > = RefetchInexactDynamicResponse & RefetchExactDynamicResponse; export type RefetchInexact = ( data?: unknown, ) => RefetchFnInexact; export type RefetchInexactDynamicResponse = ReturnType< RefetchInexact >; export type RefetchExact = ( data?: unknown | null, ) => RefetchFnExact; export type RefetchExactDynamicResponse = ReturnType< RefetchExact >; export type RefetchFnBase = (vars: TVars, options?: TOptions) => Disposable; export type RefetchFnExact = RefetchFnBase< VariablesOf, TOptions >; export type RefetchFnInexact = RefetchFnBase< Partial>, TOptions >; // NOTE: This is the "ReturnType" from relay, but its reserved by TypeScript. // https://github.com/facebook/relay/blob/676660dc86d498624d14dc50278563fc42c3fa7d/packages/relay-experimental/useRefetchableFragmentNode.js#L77-L87 export interface ReturnTypeNode< TQuery extends OperationType, TKey extends KeyType | null | undefined, TOptions = Options, > { fragmentData: unknown; fragmentRef: unknown; refetch: RefetchFnDynamic; disableStoreUpdates: () => void; enableStoreUpdates: () => void; } export interface Options { fetchPolicy?: FetchPolicy | undefined; onComplete?: ((arg: Error | null) => void) | undefined; UNSTABLE_renderPolicy?: RenderPolicy | undefined; } export interface InternalOptions extends Options { __environment?: IEnvironment | undefined; } export type Action = | { type: "reset"; environment: IEnvironment; fragmentIdentifier: string; } | { type: "refetch"; refetchVariables: Variables; fetchPolicy?: FetchPolicy | undefined; renderPolicy?: RenderPolicy | undefined; onComplete?: ((args: Error | null) => void) | undefined; environment?: IEnvironment | null | undefined; }; export interface RefetchState { fetchPolicy?: FetchPolicy | undefined; renderPolicy?: RenderPolicy | undefined; mirroredEnvironment: IEnvironment; mirroredFragmentIdentifier: string; onComplete?: ((arg: Error | null) => void) | undefined; refetchEnvironment?: IEnvironment | null | undefined; refetchVariables?: Variables | null | undefined; refetchGeneration: number; } export interface DebugIDandTypename { id: string; typename: string; } // eslint-disable-next-line @definitelytyped/no-unnecessary-generics export function useRefetchableFragmentNode( fragmentNode: ReaderFragment, parentFragmentRef: unknown, componentDisplayName: string, ): ReturnTypeNode;