apollo-cache-inmemory

  • Version 1.6.6
  • Published
  • 853 kB
  • 5 dependencies
  • MIT license

Install

npm i apollo-cache-inmemory
yarn add apollo-cache-inmemory
pnpm add apollo-cache-inmemory

Overview

Core abstract of Caching layer for Apollo Client

Index

Functions

function assertIdValue

assertIdValue: (idValue: any) => void;

    function defaultDataIdFromObject

    defaultDataIdFromObject: (result: any) => string | null;

      function defaultNormalizedCacheFactory

      defaultNormalizedCacheFactory: (seed?: NormalizedCacheObject) => NormalizedCache;

        function enhanceErrorWithDocument

        enhanceErrorWithDocument: (error: Error, document: any) => WriteError;

          Classes

          class HeuristicFragmentMatcher

          class HeuristicFragmentMatcher implements FragmentMatcherInterface {}

            constructor

            constructor();

              method canBypassInit

              canBypassInit: () => boolean;

                method ensureReady

                ensureReady: () => Promise<void>;

                  method match

                  match: (
                  idValue: any,
                  typeCondition: string,
                  context: ReadStoreContext
                  ) => boolean | 'heuristic';

                    class InMemoryCache

                    class InMemoryCache extends ApolloCache<NormalizedCacheObject> {}

                      constructor

                      constructor(config?: InMemoryCacheConfig);

                        property config

                        protected config: InMemoryCacheConfig;

                          method broadcastWatches

                          protected broadcastWatches: () => void;

                            method diff

                            diff: <T>(query: any) => any;

                              method evict

                              evict: (query: any) => any;

                                method extract

                                extract: (optimistic?: boolean) => NormalizedCacheObject;

                                  method performTransaction

                                  performTransaction: (transaction: any, optimisticId?: string) => void;

                                    method read

                                    read: <T>(options: any) => T | null;

                                      method recordOptimisticTransaction

                                      recordOptimisticTransaction: (transaction: any, id: string) => void;

                                        method removeOptimistic

                                        removeOptimistic: (idToRemove: string) => void;

                                          method reset

                                          reset: () => Promise<void>;

                                            method restore

                                            restore: (data: NormalizedCacheObject) => this;

                                              method transformDocument

                                              transformDocument: (document: any) => any;

                                                method watch

                                                watch: (watch: any) => () => void;

                                                  method write

                                                  write: (write: any) => void;

                                                    class IntrospectionFragmentMatcher

                                                    class IntrospectionFragmentMatcher implements FragmentMatcherInterface {}

                                                      constructor

                                                      constructor(options?: {
                                                      introspectionQueryResultData?: IntrospectionResultData;
                                                      });

                                                        method match

                                                        match: (
                                                        idValue: any,
                                                        typeCondition: string,
                                                        context: ReadStoreContext
                                                        ) => boolean;

                                                          class ObjectCache

                                                          class ObjectCache implements NormalizedCache {}

                                                            constructor

                                                            constructor(data?: NormalizedCacheObject);

                                                              property data

                                                              protected data: NormalizedCacheObject;

                                                                method clear

                                                                clear: () => void;

                                                                  method delete

                                                                  delete: (dataId: string) => void;

                                                                    method get

                                                                    get: (dataId: string) => StoreObject;

                                                                      method replace

                                                                      replace: (newData: NormalizedCacheObject) => void;

                                                                        method set

                                                                        set: (dataId: string, value: StoreObject) => void;

                                                                          method toObject

                                                                          toObject: () => NormalizedCacheObject;

                                                                            class StoreReader

                                                                            class StoreReader {}

                                                                              constructor

                                                                              constructor({ cacheKeyRoot, freezeResults }?: StoreReaderConfig);

                                                                                method diffQueryAgainstStore

                                                                                diffQueryAgainstStore: <T>({
                                                                                store,
                                                                                query,
                                                                                variables,
                                                                                previousResult,
                                                                                returnPartialData,
                                                                                rootId,
                                                                                fragmentMatcherFunction,
                                                                                config,
                                                                                }: DiffQueryAgainstStoreOptions) => any;

                                                                                  method readQueryFromStore

                                                                                  readQueryFromStore: <QueryType>(
                                                                                  options: ReadQueryOptions
                                                                                  ) => QueryType | undefined;

                                                                                    class StoreWriter

                                                                                    class StoreWriter {}

                                                                                      method writeQueryToStore

                                                                                      writeQueryToStore: ({
                                                                                      query,
                                                                                      result,
                                                                                      store,
                                                                                      variables,
                                                                                      dataIdFromObject,
                                                                                      fragmentMatcherFunction,
                                                                                      }: {
                                                                                      query: DocumentNode;
                                                                                      result: Object;
                                                                                      store?: NormalizedCache;
                                                                                      variables?: Object;
                                                                                      dataIdFromObject?: IdGetter;
                                                                                      fragmentMatcherFunction?: FragmentMatcher;
                                                                                      }) => NormalizedCache;

                                                                                        method writeResultToStore

                                                                                        writeResultToStore: ({
                                                                                        dataId,
                                                                                        result,
                                                                                        document,
                                                                                        store,
                                                                                        variables,
                                                                                        dataIdFromObject,
                                                                                        fragmentMatcherFunction,
                                                                                        }: {
                                                                                        dataId: string;
                                                                                        result: any;
                                                                                        document: DocumentNode;
                                                                                        store?: NormalizedCache;
                                                                                        variables?: Object;
                                                                                        dataIdFromObject?: IdGetter;
                                                                                        fragmentMatcherFunction?: FragmentMatcher;
                                                                                        }) => NormalizedCache;

                                                                                          method writeSelectionSetToStore

                                                                                          writeSelectionSetToStore: ({
                                                                                          result,
                                                                                          dataId,
                                                                                          selectionSet,
                                                                                          context,
                                                                                          }: {
                                                                                          dataId: string;
                                                                                          result: any;
                                                                                          selectionSet: SelectionSetNode;
                                                                                          context: WriteContext;
                                                                                          }) => NormalizedCache;

                                                                                            class WriteError

                                                                                            class WriteError extends Error {}

                                                                                              property type

                                                                                              type: string;

                                                                                                Interfaces

                                                                                                interface FragmentMatcherInterface

                                                                                                interface FragmentMatcherInterface {}

                                                                                                  method match

                                                                                                  match: (
                                                                                                  idValue: any,
                                                                                                  typeCondition: string,
                                                                                                  context: ReadStoreContext
                                                                                                  ) => boolean | 'heuristic';

                                                                                                    interface IdGetterObj

                                                                                                    interface IdGetterObj extends Object {}

                                                                                                      property id

                                                                                                      id?: string;

                                                                                                        interface InMemoryCacheConfig

                                                                                                        interface InMemoryCacheConfig extends ApolloReducerConfig {}

                                                                                                          property freezeResults

                                                                                                          freezeResults?: boolean;

                                                                                                            property resultCaching

                                                                                                            resultCaching?: boolean;

                                                                                                              interface NormalizedCache

                                                                                                              interface NormalizedCache {}

                                                                                                                method clear

                                                                                                                clear: () => void;

                                                                                                                  method delete

                                                                                                                  delete: (dataId: string) => void;

                                                                                                                    method get

                                                                                                                    get: (dataId: string) => StoreObject;

                                                                                                                      method replace

                                                                                                                      replace: (newData: NormalizedCacheObject) => void;

                                                                                                                        method set

                                                                                                                        set: (dataId: string, value: StoreObject) => void;

                                                                                                                          method toObject

                                                                                                                          toObject: () => NormalizedCacheObject;

                                                                                                                            interface NormalizedCacheObject

                                                                                                                            interface NormalizedCacheObject {}

                                                                                                                              index signature

                                                                                                                              [dataId: string]: StoreObject | undefined;

                                                                                                                                interface StoreObject

                                                                                                                                interface StoreObject {}

                                                                                                                                  index signature

                                                                                                                                  [storeFieldKey: string]: StoreValue;

                                                                                                                                    interface StoreReaderConfig

                                                                                                                                    interface StoreReaderConfig {}

                                                                                                                                      property cacheKeyRoot

                                                                                                                                      cacheKeyRoot?: KeyTrie<object>;

                                                                                                                                        property freezeResults

                                                                                                                                        freezeResults?: boolean;

                                                                                                                                          Type Aliases

                                                                                                                                          type ApolloReducerConfig

                                                                                                                                          type ApolloReducerConfig = {
                                                                                                                                          dataIdFromObject?: IdGetter;
                                                                                                                                          fragmentMatcher?: FragmentMatcherInterface;
                                                                                                                                          addTypename?: boolean;
                                                                                                                                          cacheRedirects?: CacheResolverMap;
                                                                                                                                          };

                                                                                                                                            type CacheResolver

                                                                                                                                            type CacheResolver = (
                                                                                                                                            rootValue: any,
                                                                                                                                            args: {
                                                                                                                                            [argName: string]: any;
                                                                                                                                            },
                                                                                                                                            context: any
                                                                                                                                            ) => any;

                                                                                                                                              type CacheResolverMap

                                                                                                                                              type CacheResolverMap = {
                                                                                                                                              [typeName: string]: {
                                                                                                                                              [fieldName: string]: CacheResolver;
                                                                                                                                              };
                                                                                                                                              };

                                                                                                                                                type CustomResolver

                                                                                                                                                type CustomResolver = CacheResolver;

                                                                                                                                                  type CustomResolverMap

                                                                                                                                                  type CustomResolverMap = CacheResolverMap;

                                                                                                                                                    type DiffQueryAgainstStoreOptions

                                                                                                                                                    type DiffQueryAgainstStoreOptions = ReadQueryOptions & {
                                                                                                                                                    returnPartialData?: boolean;
                                                                                                                                                    };

                                                                                                                                                      type ExecResult

                                                                                                                                                      type ExecResult<R = any> = {
                                                                                                                                                      result: R;
                                                                                                                                                      missing?: ExecResultMissingField[];
                                                                                                                                                      };

                                                                                                                                                        type ExecResultMissingField

                                                                                                                                                        type ExecResultMissingField = {
                                                                                                                                                        object: StoreObject;
                                                                                                                                                        fieldName: string;
                                                                                                                                                        tolerable: boolean;
                                                                                                                                                        };

                                                                                                                                                          type FragmentMatcher

                                                                                                                                                          type FragmentMatcher = (
                                                                                                                                                          rootValue: any,
                                                                                                                                                          typeCondition: string,
                                                                                                                                                          context: ReadStoreContext
                                                                                                                                                          ) => boolean | 'heuristic';

                                                                                                                                                            type IdGetter

                                                                                                                                                            type IdGetter = (value: IdGetterObj) => string | null | undefined;

                                                                                                                                                              type IntrospectionResultData

                                                                                                                                                              type IntrospectionResultData = {
                                                                                                                                                              __schema: {
                                                                                                                                                              types: {
                                                                                                                                                              kind: string;
                                                                                                                                                              name: string;
                                                                                                                                                              possibleTypes: {
                                                                                                                                                              name: string;
                                                                                                                                                              }[];
                                                                                                                                                              }[];
                                                                                                                                                              };
                                                                                                                                                              };

                                                                                                                                                                type OptimisticStoreItem

                                                                                                                                                                type OptimisticStoreItem = {
                                                                                                                                                                id: string;
                                                                                                                                                                data: NormalizedCacheObject;
                                                                                                                                                                transaction: Transaction<NormalizedCacheObject>;
                                                                                                                                                                };

                                                                                                                                                                  type PossibleTypesMap

                                                                                                                                                                  type PossibleTypesMap = {
                                                                                                                                                                  [key: string]: string[];
                                                                                                                                                                  };

                                                                                                                                                                    type ReadQueryOptions

                                                                                                                                                                    type ReadQueryOptions = {
                                                                                                                                                                    store: NormalizedCache;
                                                                                                                                                                    query: DocumentNode;
                                                                                                                                                                    fragmentMatcherFunction?: FragmentMatcher;
                                                                                                                                                                    variables?: Object;
                                                                                                                                                                    previousResult?: any;
                                                                                                                                                                    rootId?: string;
                                                                                                                                                                    config?: ApolloReducerConfig;
                                                                                                                                                                    };

                                                                                                                                                                      type ReadStoreContext

                                                                                                                                                                      type ReadStoreContext = {
                                                                                                                                                                      readonly store: NormalizedCache;
                                                                                                                                                                      readonly cacheRedirects: CacheResolverMap;
                                                                                                                                                                      readonly dataIdFromObject?: IdGetter;
                                                                                                                                                                      };

                                                                                                                                                                        type VariableMap

                                                                                                                                                                        type VariableMap = {
                                                                                                                                                                        [name: string]: any;
                                                                                                                                                                        };

                                                                                                                                                                          type WriteContext

                                                                                                                                                                          type WriteContext = {
                                                                                                                                                                          readonly store: NormalizedCache;
                                                                                                                                                                          readonly processedData?: {
                                                                                                                                                                          [x: string]: FieldNode[];
                                                                                                                                                                          };
                                                                                                                                                                          readonly variables?: any;
                                                                                                                                                                          readonly dataIdFromObject?: IdGetter;
                                                                                                                                                                          readonly fragmentMap?: FragmentMap;
                                                                                                                                                                          readonly fragmentMatcherFunction?: FragmentMatcher;
                                                                                                                                                                          };

                                                                                                                                                                            Package Files (7)

                                                                                                                                                                            Dependencies (5)

                                                                                                                                                                            Dev Dependencies (0)

                                                                                                                                                                            No dev dependencies.

                                                                                                                                                                            Peer Dependencies (1)

                                                                                                                                                                            Badge

                                                                                                                                                                            To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                                                                                            You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/apollo-cache-inmemory.

                                                                                                                                                                            • Markdown
                                                                                                                                                                              [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/apollo-cache-inmemory)
                                                                                                                                                                            • HTML
                                                                                                                                                                              <a href="https://www.jsdocs.io/package/apollo-cache-inmemory"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>