@twilio/flex-sdk
    Preparing search index...

    Interface FlexDataClient

    This is the primary Apollo Client class. It is used to send GraphQL documents (i.e. queries and mutations) to a GraphQL spec-compliant server over an ApolloLink instance, receive results from the server and cache the results in a store. It also delivers updates to GraphQL queries through Observable instances.

    interface FlexDataClient {
        cache: ApolloCache;
        defaultOptions: DefaultOptions;
        devtoolsConfig: DevtoolsOptions;
        disableNetworkFetches: never;
        getMemoryInternals?: () => {
            limits: { [k: string]: number };
            sizes: {
                addTypenameDocumentTransform?: { cache: number }[];
                cache?: { fragmentQueryDocuments: number | undefined };
                canonicalStringify: number | undefined;
                fragmentRegistry?: {
                    findFragmentSpreads: number | undefined;
                    lookup: number | undefined;
                    transform: number | undefined;
                };
                inMemoryCache?: {
                    executeSelectionSet: number
                    | undefined;
                    executeSubSelectedArray: number | undefined;
                    maybeBroadcastWatch: number | undefined;
                };
                links: unknown[];
                print: number
                | undefined;
                queryManager: {
                    documentTransforms: { cache: number }[];
                    getDocumentInfo: number;
                };
            };
        };
        link: FlexDataClientLink;
        queryDeduplication: boolean;
        reFetchObservableQueries: (
            includeStandby?: boolean,
        ) => Promise<QueryResult<any>[]>;
        version: string;
        get defaultContext(): Partial<DefaultContext>;
        get documentTransform(): DocumentTransform;
        get localState(): | LocalState<Resolvers<DefaultContext>, DefaultContext>
        | undefined;
        set localState(localState: LocalState): void;
        get prioritizeCacheValues(): boolean;
        set prioritizeCacheValues(value: boolean): void;
        __actionHookForDevTools(cb: () => any): void;
        __requestRaw(
            request: Request,
        ): Observable<FormattedExecutionResult<unknown, Record<string, any>>>;
        clearStore(): Promise<any[]>;
        extract(optimistic?: boolean): unknown;
        getObservableQueries(
            include?: RefetchQueriesInclude,
        ): Set<ObservableQuery<any, OperationVariables>>;
        mutate<
            TData = unknown,
            TVariables extends OperationVariables = OperationVariables,
            TCache extends ApolloCache = ApolloCache,
        >(
            options: MutateOptions<TData, TVariables, TCache>,
        ): Promise<MutateResult<TData>>;
        onClearStore(cb: () => Promise<any>): () => void;
        onResetStore(cb: () => Promise<any>): () => void;
        query<
            TData = unknown,
            TVariables extends OperationVariables = OperationVariables,
        >(
            options: QueryOptions<TData, TVariables>,
        ): Promise<QueryResult<TData>>;
        readFragment<
            TData = unknown,
            TVariables extends OperationVariables = OperationVariables,
        >(
            options: FlexDataClient.ReadFragmentOptions<TData, TVariables>,
        ): TData | null;
        readFragment<
            TData = unknown,
            TVariables extends OperationVariables = OperationVariables,
        >(
            options: FlexDataClient.ReadFragmentOptions<TData, TVariables>,
            optimistic: boolean,
        ): TData | null;
        readQuery<
            TData = unknown,
            TVariables extends OperationVariables = OperationVariables,
        >(
            options: FlexDataClient.ReadQueryOptions<TData, TVariables>,
        ): TData | null;
        readQuery<
            TData = unknown,
            TVariables extends OperationVariables = OperationVariables,
        >(
            options: FlexDataClient.ReadQueryOptions<TData, TVariables>,
            optimistic: boolean,
        ): TData | null;
        refetchObservableQueries(
            includeStandby?: boolean,
        ): Promise<QueryResult<any>[]>;
        refetchQueries<
            TCache extends ApolloCache = ApolloCache,
            TResult = Promise<QueryResult<any>>,
        >(
            options: RefetchQueriesOptions<TCache, TResult>,
        ): FlexDataClient.RefetchQueriesResult<TResult>;
        resetStore(): Promise<QueryResult<any>[] | null>;
        restore(serializedState: unknown): ApolloCache;
        setLink(newLink: FlexDataClientLink): void;
        stop(): void;
        subscribe<
            TData = unknown,
            TVariables extends OperationVariables = OperationVariables,
        >(
            options: SubscribeOptions<TData, TVariables>,
        ): SubscriptionObservable<SubscribeResult<TData>>;
        watchFragment<
            TData = unknown,
            TVariables extends OperationVariables = OperationVariables,
        >(
            options: WatchFragmentOptions<TData, TVariables> & {
                from: FromOptionValue<TData>[];
            },
        ): ObservableFragment<TData[]>;
        watchFragment<
            TData = unknown,
            TVariables extends OperationVariables = OperationVariables,
        >(
            options: WatchFragmentOptions<TData, TVariables> & { from: null[] },
        ): ObservableFragment<null[]>;
        watchFragment<
            TData = unknown,
            TVariables extends OperationVariables = OperationVariables,
        >(
            options: WatchFragmentOptions<TData, TVariables> & {
                from: (FromOptionValue<TData> | null)[];
            },
        ): ObservableFragment<(TData | null)[]>;
        watchFragment<
            TData = unknown,
            TVariables extends OperationVariables = OperationVariables,
        >(
            options: WatchFragmentOptions<TData, TVariables> & { from: null },
        ): ObservableFragment<null>;
        watchFragment<
            TData = unknown,
            TVariables extends OperationVariables = OperationVariables,
        >(
            options: WatchFragmentOptions<TData, TVariables> & {
                from: FromOptionValue<TData>;
            },
        ): ObservableFragment<TData>;
        watchFragment<
            TData = unknown,
            TVariables extends OperationVariables = OperationVariables,
        >(
            options: WatchFragmentOptions<TData, TVariables>,
        ): ObservableFragment<TData | null>;
        watchQuery<
            TData = unknown,
            TVariables extends OperationVariables = OperationVariables,
        >(
            options: WatchQueryOptions<TData, TVariables>,
        ): ObservableQuery<TData, TVariables>;
        writeFragment<
            TData = unknown,
            TVariables extends OperationVariables = OperationVariables,
        >(
            options: FlexDataClient.WriteFragmentOptions<TData, TVariables>,
        ): Reference | undefined;
        writeQuery<
            TData = unknown,
            TVariables extends OperationVariables = OperationVariables,
        >(
            options: FlexDataClient.WriteQueryOptions<TData, TVariables>,
        ): Reference | undefined;
    }
    Index

    Properties

    cache: ApolloCache
    defaultOptions: DefaultOptions
    devtoolsConfig: DevtoolsOptions
    disableNetworkFetches: never

    disableNetworkFetches has been renamed to prioritizeCacheValues.

    getMemoryInternals?: () => {
        limits: { [k: string]: number };
        sizes: {
            addTypenameDocumentTransform?: { cache: number }[];
            cache?: { fragmentQueryDocuments: number | undefined };
            canonicalStringify: number | undefined;
            fragmentRegistry?: {
                findFragmentSpreads: number | undefined;
                lookup: number | undefined;
                transform: number | undefined;
            };
            inMemoryCache?: {
                executeSelectionSet: number
                | undefined;
                executeSubSelectedArray: number | undefined;
                maybeBroadcastWatch: number | undefined;
            };
            links: unknown[];
            print: number
            | undefined;
            queryManager: {
                documentTransforms: { cache: number }[];
                getDocumentInfo: number;
            };
        };
    }

    This is not a stable API - it is used in development builds to expose information to the DevTools. Use at your own risk! For more details, see Memory Management

    console.log(client.getMemoryInternals());
    

    Logs output in the following JSON format:

    {
    "limits": {
    "canonicalStringify": 1000,
    "print": 2000,
    "documentTransform.cache": 2000,
    "queryManager.getDocumentInfo": 2000,
    "PersistedQueryLink.persistedQueryHashes": 2000,
    "fragmentRegistry.transform": 2000,
    "fragmentRegistry.lookup": 1000,
    "fragmentRegistry.findFragmentSpreads": 4000,
    "cache.fragmentQueryDocuments": 1000,
    "removeTypenameFromVariables.getVariableDefinitions": 2000,
    "inMemoryCache.maybeBroadcastWatch": 5000,
    "inMemoryCache.executeSelectionSet": 10000,
    "inMemoryCache.executeSubSelectedArray": 5000
    },
    "sizes": {
    "canonicalStringify": 4,
    "print": 14,
    "addTypenameDocumentTransform": [
    {
    "cache": 14
    }
    ],
    "queryManager": {
    "getDocumentInfo": 14,
    "documentTransforms": [
    {
    "cache": 14
    },
    {
    "cache": 14
    }
    ]
    },
    "fragmentRegistry": {
    "findFragmentSpreads": 34,
    "lookup": 20,
    "transform": 14
    },
    "cache": {
    "fragmentQueryDocuments": 22
    },
    "inMemoryCache": {
    "executeSelectionSet": 4345,
    "executeSubSelectedArray": 1206,
    "maybeBroadcastWatch": 32
    },
    "links": [
    {
    "PersistedQueryLink": {
    "persistedQueryHashes": 14
    }
    },
    {
    "removeTypenameFromVariables": {
    "getVariableDefinitions": 14
    }
    }
    ]
    }
    }
    queryDeduplication: boolean
    reFetchObservableQueries: (
        includeStandby?: boolean,
    ) => Promise<QueryResult<any>[]>

    Refetches all of your active queries.

    reFetchObservableQueries() is useful if you want to bring the client back to proper state in case of a network outage

    It is important to remember that reFetchObservableQueries() will refetch any active queries. This means that any components that might be mounted will execute their queries again using your network interface. If you do not want to re-execute any queries then you should make sure to stop watching any active queries. Takes optional parameter includeStandby which will include queries in standby-mode when refetching.

    Note: cache-only queries are not refetched by this function.

    Please use refetchObservableQueries instead.

    version: string

    Accessors

    • get defaultContext(): Partial<DefaultContext>

      Returns Partial<DefaultContext>

    • get documentTransform(): DocumentTransform

      The DocumentTransform used to modify GraphQL documents before a request is made. If a custom DocumentTransform is not provided, this will be the default document transform.

      Returns DocumentTransform

    • get localState(): | LocalState<Resolvers<DefaultContext>, DefaultContext>
      | undefined

      The configured LocalState instance used to enable the use of @client fields.

      Returns LocalState<Resolvers<DefaultContext>, DefaultContext> | undefined

    • set localState(localState: LocalState): void

      Parameters

      Returns void

    • get prioritizeCacheValues(): boolean

      Whether to prioritize cache values over network results when query or watchQuery is called. This will essentially turn a "network-only" or "cache-and-network" fetchPolicy into a "cache-first" fetchPolicy, but without influencing the fetchPolicy of the created ObservableQuery long-term.

      This can e.g. be used to prioritize the cache during the first render after SSR.

      Returns boolean

    • set prioritizeCacheValues(value: boolean): void

      Parameters

      • value: boolean

      Returns void

    Methods

    • Parameters

      • cb: () => any

      Returns void

    • Parameters

      Returns Observable<FormattedExecutionResult<unknown, Record<string, any>>>

    • Remove all data from the store. Unlike resetStore, clearStore will not refetch any active queries.

      Returns Promise<any[]>

    • Exposes the cache's complete state, in a serializable format for later restoration.

      Parameters

      • Optionaloptimistic: boolean

        Determines whether the result contains data from the optimistic layer

      Returns unknown

      This can be useful for debugging in order to inspect the full state of the cache.

    • Get all currently active ObservableQuery objects, in a Set.

      An "active" query is one that has observers and a fetchPolicy other than "standby" or "cache-only".

      You can include all ObservableQuery objects (including the inactive ones) by passing "all" instead of "active", or you can include just a subset of active queries by passing an array of query names or DocumentNode objects.

      Note: This method only returns queries that have active subscribers. Queries without subscribers are not tracked by the client.

      Parameters

      • Optionalinclude: RefetchQueriesInclude

      Returns Set<ObservableQuery<any, OperationVariables>>

    • This resolves a single mutation according to the options specified and returns a Promise which is either resolved with the resulting data or rejected with an error. In some cases both data and errors might be undefined, for example when errorPolicy is set to 'ignore'.

      It takes options as an object with the following keys and values:

      Type Parameters

      • TData = unknown
      • TVariables extends OperationVariables = OperationVariables
      • TCache extends ApolloCache = ApolloCache

      Parameters

      Returns Promise<MutateResult<TData>>

    • Allows callbacks to be registered that are executed when the store is cleared. onClearStore returns an unsubscribe function that can be used to remove registered callbacks.

      Parameters

      • cb: () => Promise<any>

      Returns () => void

    • Allows callbacks to be registered that are executed when the store is reset. onResetStore returns an unsubscribe function that can be used to remove registered callbacks.

      Parameters

      • cb: () => Promise<any>

      Returns () => void

    • This resolves a single query according to the options specified and returns a Promise which is either resolved with the resulting data or rejected with an error.

      Type Parameters

      • TData = unknown
      • TVariables extends OperationVariables = OperationVariables

      Parameters

      • options: QueryOptions<TData, TVariables>

        An object of type QueryOptions that allows us to describe how this query should be treated e.g. whether it should hit the server at all or just resolve from the cache, etc.

      Returns Promise<QueryResult<TData>>

    • Tries to read some data from the store in the shape of the provided GraphQL fragment without making a network request. This method will read a GraphQL fragment from any arbitrary id that is currently cached, unlike readQuery which will only read from the root query.

      You must pass in a GraphQL document with a single fragment or a document with multiple fragments that represent what you are reading. If you pass in a document with multiple fragments then you must also specify a fragmentName.

      Type Parameters

      • TData = unknown
      • TVariables extends OperationVariables = OperationVariables

      Returns TData | null

    • Tries to read some data from the store in the shape of the provided GraphQL fragment without making a network request. This method will read a GraphQL fragment from any arbitrary id that is currently cached, unlike readQuery which will only read from the root query.

      You must pass in a GraphQL document with a single fragment or a document with multiple fragments that represent what you are reading. If you pass in a document with multiple fragments then you must also specify a fragmentName.

      Type Parameters

      • TData = unknown
      • TVariables extends OperationVariables = OperationVariables

      Parameters

      Returns TData | null

      Pass the optimistic argument as part of the first argument instead of passing it as a separate option.

    • Tries to read some data from the store in the shape of the provided GraphQL query without making a network request. This method will start at the root query. To start at a specific id returned by cache.identify use readFragment.

      Type Parameters

      • TData = unknown
      • TVariables extends OperationVariables = OperationVariables

      Returns TData | null

    • Tries to read some data from the store in the shape of the provided GraphQL query without making a network request. This method will start at the root query. To start at a specific id returned by cache.identify use readFragment.

      Type Parameters

      • TData = unknown
      • TVariables extends OperationVariables = OperationVariables

      Parameters

      Returns TData | null

      Pass the optimistic argument as part of the first argument instead of passing it as a separate option.

    • Refetches all of your active queries.

      refetchObservableQueries() is useful if you want to bring the client back to proper state in case of a network outage

      It is important to remember that refetchObservableQueries() will refetch any active queries. This means that any components that might be mounted will execute their queries again using your network interface. If you do not want to re-execute any queries then you should make sure to stop watching any active queries. Takes optional parameter includeStandby which will include queries in standby-mode when refetching.

      Note: cache-only queries are not refetched by this function.

      Parameters

      • OptionalincludeStandby: boolean

      Returns Promise<QueryResult<any>[]>

    • Refetches specified active queries. Similar to "refetchObservableQueries()" but with a specific list of queries.

      refetchQueries() is useful for use cases to imperatively refresh a selection of queries.

      It is important to remember that refetchQueries() will refetch specified active queries. This means that any components that might be mounted will execute their queries again using your network interface. If you do not want to re-execute any queries then you should make sure to stop watching any active queries.

      Type Parameters

      • TCache extends ApolloCache = ApolloCache
      • TResult = Promise<QueryResult<any>>

      Parameters

      Returns FlexDataClient.RefetchQueriesResult<TResult>

    • Resets your entire store by clearing out your cache and then re-executing all of your active queries. This makes it so that you may guarantee that there is no data left in your store from a time before you called this method.

      resetStore() is useful when your user just logged out. You’ve removed the user session, and you now want to make sure that any references to data you might have fetched while the user session was active is gone.

      It is important to remember that resetStore() will refetch any active queries. This means that any components that might be mounted will execute their queries again using your network interface. If you do not want to re-execute any queries then you should make sure to stop watching any active queries.

      Returns Promise<QueryResult<any>[] | null>

    • Replaces existing state in the cache (if any) with the values expressed by serializedState.

      Called when hydrating a cache (server side rendering, or offline storage), and also (potentially) during hot reloads.

      Parameters

      • serializedState: unknown

      Returns ApolloCache

    • Call this method to terminate any active client processes, making it safe to dispose of this ApolloClient instance.

      This method performs aggressive cleanup to prevent memory leaks:

      • Unsubscribes all active ObservableQuery instances by emitting a completed event
      • Rejects all currently running queries with "QueryManager stopped while query was in flight"
      • Removes all queryRefs from the suspense cache

      Returns void

    • Watches the cache store of the fragment according to the options specified and returns an Observable. We can subscribe to this Observable and receive updated results through an observer when the cache store changes.

      You must pass in a GraphQL document with a single fragment or a document with multiple fragments that represent what you are reading. If you pass in a document with multiple fragments then you must also specify a fragmentName.

      Type Parameters

      • TData = unknown
      • TVariables extends OperationVariables = OperationVariables

      Parameters

      • options: WatchFragmentOptions<TData, TVariables> & { from: FromOptionValue<TData>[] }

        An object of type WatchFragmentOptions that allows the cache to identify the fragment and optionally specify whether to react to optimistic updates.

      Returns ObservableFragment<TData[]>

      3.10.0

    • Watches the cache store of the fragment according to the options specified and returns an Observable. We can subscribe to this Observable and receive updated results through an observer when the cache store changes.

      You must pass in a GraphQL document with a single fragment or a document with multiple fragments that represent what you are reading. If you pass in a document with multiple fragments then you must also specify a fragmentName.

      Type Parameters

      • TData = unknown
      • TVariables extends OperationVariables = OperationVariables

      Parameters

      • options: WatchFragmentOptions<TData, TVariables> & { from: null[] }

        An object of type WatchFragmentOptions that allows the cache to identify the fragment and optionally specify whether to react to optimistic updates.

      Returns ObservableFragment<null[]>

      3.10.0

    • Watches the cache store of the fragment according to the options specified and returns an Observable. We can subscribe to this Observable and receive updated results through an observer when the cache store changes.

      You must pass in a GraphQL document with a single fragment or a document with multiple fragments that represent what you are reading. If you pass in a document with multiple fragments then you must also specify a fragmentName.

      Type Parameters

      • TData = unknown
      • TVariables extends OperationVariables = OperationVariables

      Parameters

      • options: WatchFragmentOptions<TData, TVariables> & {
            from: (FromOptionValue<TData> | null)[];
        }

        An object of type WatchFragmentOptions that allows the cache to identify the fragment and optionally specify whether to react to optimistic updates.

      Returns ObservableFragment<(TData | null)[]>

      3.10.0

    • Watches the cache store of the fragment according to the options specified and returns an Observable. We can subscribe to this Observable and receive updated results through an observer when the cache store changes.

      You must pass in a GraphQL document with a single fragment or a document with multiple fragments that represent what you are reading. If you pass in a document with multiple fragments then you must also specify a fragmentName.

      Type Parameters

      • TData = unknown
      • TVariables extends OperationVariables = OperationVariables

      Parameters

      • options: WatchFragmentOptions<TData, TVariables> & { from: null }

        An object of type WatchFragmentOptions that allows the cache to identify the fragment and optionally specify whether to react to optimistic updates.

      Returns ObservableFragment<null>

      3.10.0

    • Watches the cache store of the fragment according to the options specified and returns an Observable. We can subscribe to this Observable and receive updated results through an observer when the cache store changes.

      You must pass in a GraphQL document with a single fragment or a document with multiple fragments that represent what you are reading. If you pass in a document with multiple fragments then you must also specify a fragmentName.

      Type Parameters

      • TData = unknown
      • TVariables extends OperationVariables = OperationVariables

      Parameters

      • options: WatchFragmentOptions<TData, TVariables> & { from: FromOptionValue<TData> }

        An object of type WatchFragmentOptions that allows the cache to identify the fragment and optionally specify whether to react to optimistic updates.

      Returns ObservableFragment<TData>

      3.10.0

    • Watches the cache store of the fragment according to the options specified and returns an Observable. We can subscribe to this Observable and receive updated results through an observer when the cache store changes.

      You must pass in a GraphQL document with a single fragment or a document with multiple fragments that represent what you are reading. If you pass in a document with multiple fragments then you must also specify a fragmentName.

      Type Parameters

      • TData = unknown
      • TVariables extends OperationVariables = OperationVariables

      Parameters

      • options: WatchFragmentOptions<TData, TVariables>

        An object of type WatchFragmentOptions that allows the cache to identify the fragment and optionally specify whether to react to optimistic updates.

      Returns ObservableFragment<TData | null>

      3.10.0

    • This watches the cache store of the query according to the options specified and returns an ObservableQuery. We can subscribe to this ObservableQuery and receive updated results through an observer when the cache store changes.

      Note that this method is not an implementation of GraphQL subscriptions. Rather, it uses Apollo's store in order to reactively deliver updates to your query results.

      For example, suppose you call watchQuery on a GraphQL query that fetches a person's first and last name and this person has a particular object identifier, provided by cache.identify. Later, a different query fetches that same person's first and last name and the first name has now changed. Then, any observers associated with the results of the first query will be updated with a new result object.

      Note that if the cache does not change, the subscriber will not be notified.

      See here for a description of store reactivity.

      Type Parameters

      • TData = unknown
      • TVariables extends OperationVariables = OperationVariables

      Parameters

      Returns ObservableQuery<TData, TVariables>

    • Writes some data in the shape of the provided GraphQL fragment directly to the store. This method will write to a GraphQL fragment from any arbitrary id that is currently cached, unlike writeQuery which will only write from the root query.

      You must pass in a GraphQL document with a single fragment or a document with multiple fragments that represent what you are writing. If you pass in a document with multiple fragments then you must also specify a fragmentName.

      Type Parameters

      • TData = unknown
      • TVariables extends OperationVariables = OperationVariables

      Returns Reference | undefined

    • Writes some data in the shape of the provided GraphQL query directly to the store. This method will start at the root query. To start at a specific id returned by cache.identify then use writeFragment.

      Type Parameters

      • TData = unknown
      • TVariables extends OperationVariables = OperationVariables

      Returns Reference | undefined