UNPKG

@apollo/client

Version:

A fully-featured caching GraphQL client.

135 lines (134 loc) 5.15 kB
import type { DocumentNode, FieldNode } from "graphql"; import type { OperationVariables } from "@apollo/client"; import type { Reference, StoreObject, StoreValue } from "@apollo/client/utilities"; import type { DeferInfoTrie, ExtensionsWithStreamInfo, RemoveIndexSignature, StreamInfoTrie } from "@apollo/client/utilities/internal"; import type { ApolloCache, Transaction } from "../core/cache.js"; import type { AllFieldsModifier, CanReadFunction, Modifiers, ToReferenceFunction } from "../core/types/common.js"; import type { FieldValueGetter } from "./entityStore.js"; import type { FragmentRegistryAPI } from "./fragmentRegistry.js"; import type { InMemoryCache } from "./inMemoryCache.js"; import type { FieldMergeFunction, KeyFieldsFunction, PossibleTypesMap, StorageType, TypePolicies } from "./policies.js"; export type { Reference, StoreObject, StoreValue }; export interface IdGetterObj extends Object { __typename?: string; id?: string; _id?: string; } export declare type IdGetter = (value: IdGetterObj) => string | undefined; /** * This is an interface used to access, set and remove * StoreObjects from the cache */ export interface NormalizedCache { has(dataId: string): boolean; get(dataId: string, fieldName: string): StoreValue; merge(olderId: string, newerObject: StoreObject): void; merge(olderObject: StoreObject, newerId: string): void; modify<Entity extends Record<string, any>>(dataId: string, fields: Modifiers<Entity> | AllFieldsModifier<Entity>, exact: boolean): boolean; delete(dataId: string, fieldName?: string): boolean; clear(): void; /** * returns an Object with key-value pairs matching the contents of the store */ toObject(): NormalizedCacheObject; /** * replace the state of the store */ replace(newData: NormalizedCacheObject): void; /** * Retain (or release) a given root ID to protect (or expose) it and its * transitive child entities from (or to) garbage collection. The current * retainment count is returned by both methods. Note that releasing a root * ID does not cause that entity to be garbage collected, but merely removes * it from the set of root IDs that will be considered during the next * mark-and-sweep collection. */ retain(rootId: string): number; release(rootId: string): number; getFieldValue: FieldValueGetter; toReference: ToReferenceFunction; canRead: CanReadFunction; getStorage(idOrObj: string | StoreObject, ...storeFieldNames: (string | number)[]): StorageType; } /** * This is a normalized representation of the Apollo query result cache. It consists of * a flattened representation of query result trees. */ export interface NormalizedCacheObject { __META?: { extraRootIds: string[]; }; [dataId: string]: StoreObject | undefined; } export type OptimisticStoreItem = { id: string; data: NormalizedCacheObject; transaction: Transaction; }; export type ReadQueryOptions = { /** * The Apollo Client store object. */ store: NormalizedCache; /** * A parsed GraphQL query document. */ query: DocumentNode; variables?: Object; previousResult?: any; rootId?: string; config?: ApolloReducerConfig; }; /** * @internal * * @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time. */ export interface DiffIncrementalInfo { streamInfo?: StreamInfoTrie; deferInfo?: DeferInfoTrie; } export type DiffQueryAgainstStoreOptions = ReadQueryOptions & { returnPartialData?: boolean; }; export type ApolloReducerConfig = { dataIdFromObject?: KeyFieldsFunction; }; export interface InputObjectConfig { fields: Record<string, string>; } export interface InputObjectsOption { [inputObjectName: string]: InputObjectConfig; } export type InMemoryCacheConfig = ApolloReducerConfig & { resultCaching?: boolean; possibleTypes?: PossibleTypesMap; typePolicies?: TypePolicies; fragments?: FragmentRegistryAPI; inputObjects?: InputObjectsOption; } & ({} extends InMemoryCache.ScalarsOption ? InMemoryCache.ScalarsOption extends Record<string, never> ? { scalars?: Record<string, `Scalar types must be declared in ApolloCache.Scalars before usage. See https://www.apollographql.com/docs/react/data/typescript#declaring-scalar-types.`>; } : { scalars?: InMemoryCache.ScalarsOption; } : { scalars: InMemoryCache.ScalarsOption; }); export interface MergeInfo { field: FieldNode; typename: string | undefined; merge: FieldMergeFunction; path: Array<string | number>; } export interface MergeTree { info?: MergeInfo; map: Map<string | number, MergeTree>; } export interface ReadMergeModifyContext { store: NormalizedCache; variables?: OperationVariables; varString?: string; extensions?: ExtensionsWithStreamInfo; } export type KnownScalars = RemoveIndexSignature<ApolloCache.Scalars>; export type ScalarNames = keyof KnownScalars | (string extends keyof ApolloCache.Scalars ? string & {} : never); //# sourceMappingURL=types.d.ts.map