Skip to content

Commit

Permalink
feat: expose watchFragment via public method on ApolloClient
Browse files Browse the repository at this point in the history
  • Loading branch information
alessbell committed Jan 5, 2024
1 parent 6a57465 commit 6508916
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/core/ApolloClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export interface ApolloClientOptions<TCacheShape> {
// 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 };

/**
Expand Down Expand Up @@ -468,6 +469,28 @@ export class ApolloClient<TCacheShape> implements DataProxy {
return this.cache.readQuery<T, TVariables>(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<T = any, TVariables = OperationVariables>(
options: WatchFragmentOptions<T, TVariables>
) {
return this.cache.watchFragment<T, TVariables>(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
Expand Down

0 comments on commit 6508916

Please sign in to comment.