diff --git a/src/core/ApolloClient.ts b/src/core/ApolloClient.ts index 933d4266b1e..4833be843ed 100644 --- a/src/core/ApolloClient.ts +++ b/src/core/ApolloClient.ts @@ -123,6 +123,7 @@ export interface ApolloClientOptions { // solution is to reexport mergeOptions where it was previously declared (here). import { mergeOptions } from "../utilities/index.js"; import { getApolloClientMemoryInternals } from "../utilities/caching/getMemoryInternals.js"; +import { WatchFragmentOptions } from "../cache/core/cache.js"; export { mergeOptions }; /** @@ -468,6 +469,28 @@ export class ApolloClient implements DataProxy { return this.cache.readQuery(options, optimistic); } + /** + * Watches the cache store of the fragment according to the options specified + * and returns an {@link ObservableQuery}. We can subscribe to this + * {@link ObservableQuery} and receive updated results through a GraphQL + * 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`. + * + * @param options - An object of type {@link WatchFragmentOptions} that allows + * the cache to identify the fragment and optionally specify whether to react + * to optimistic updates. + */ + + public watchFragment( + options: WatchFragmentOptions + ) { + return this.cache.watchFragment(options); + } + /** * 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