docs/source/api/core/ObservableQuery.mdx
An ObservableQuery is created by calling the client.watchQuery method.
It represents a query that can be observed for changes, allowing you to reactively update your UI.
ObservableQuery implements the RxJS InteropObservable interface which means you can convert it into an RxJS Observable via from(observableQuery).
It also provides the subscribe and pipe functions like an RxJS Observable.
Refer to the RxJS documentation for additional context and API options.
To get a single result from an ObservableQuery as a Promise, use the firstValueFrom helper:
import { firstValueFrom, from } from "rxjs";
// The `from` is necessary to turn `observableQuery` into an RxJS observable
const result = await firstValueFrom(from(observableQuery));
ObservableQuery instances are only registered with ApolloClient while they have active subscribersObservableQuery while a request is in flight does not terminate the requestObservableQuery does not terminate on errors - instead it emits a next value with an error property. This ensures ObservableQuery subscriptions can continue receiving updates after errors without resubscription.notifyOnNetworkStatusChange is true (the default), an initial loading state is emitted when subscribingObservableQuery preserves data when emitting a loading state unless query or variables changed (note: @export variables are not considered for this check)cache-only queries initialize with networkStatus: NetworkStatus.ready when there is no data in the cachestandby queries initialize with networkStatus: NetworkStatus.ready before subscribing to the queryrefetch() and reobserve() return a ResultPromise with an additional .retain() methodObservableQuery no longer requires the result, such as when ObservableQuery is unsubscribed or variables change, and the returned Promise will reject with an AbortError.retain() keeps the network operation running even when the ObservableQuery no longer requires the resultsetVariables() and refetch() guarantee that a value will be emitted from the observable, even when the result is deeply equal to the previous resultfetchPolicy of standbyfetchPolicy of standbyObservableQuerys without subscribers but with an active network request are handled as if they had a subscriber for the duration of the queryApolloClient.refetchQueriesObservableQuery functions<FunctionDetails canonicalReference="@apollo/client!ObservableQuery#getCurrentResult:member(1)" headingLevel={3} result={false} parameters={false} /> <FunctionDetails canonicalReference="@apollo/client!ObservableQuery.DocumentationTypes.ObservableMethods#pipe:member(1)" headingLevel={3} result={false} parameters={false} /> <FunctionDetails canonicalReference="@apollo/client!ObservableQuery.DocumentationTypes.ObservableMethods#subscribe:member(1)" headingLevel={3} result={false} parameters={true} /> <FunctionDetails canonicalReference="@apollo/client!ObservableQuery#refetch:member(1)" headingLevel={3} result={false} /> <FunctionDetails canonicalReference="@apollo/client!ObservableQuery#fetchMore:member(1)" headingLevel={3} result={false} parameters={false} /> <FunctionDetails canonicalReference="@apollo/client!ObservableQuery#subscribeToMore:member(1)" headingLevel={3} result={false} parameters={false} /> <FunctionDetails canonicalReference="@apollo/client!ObservableQuery#stop:member(1)" headingLevel={3} result={false} parameters={false} /> <FunctionDetails canonicalReference="@apollo/client!ObservableQuery#setVariables:member(1)" headingLevel={3} result={false} /> <FunctionDetails canonicalReference="@apollo/client!ObservableQuery#updateQuery:member(1)" headingLevel={3} result={false} parameters={false} /> <FunctionDetails canonicalReference="@apollo/client!ObservableQuery#startPolling:member(1)" headingLevel={3} result={false} parameters={false} /> <FunctionDetails canonicalReference="@apollo/client!ObservableQuery#stopPolling:member(1)" headingLevel={3} result={false} parameters={false} /> <FunctionDetails canonicalReference="@apollo/client!ObservableQuery#reobserve:member(1)" headingLevel={3} result={false} parameters={false} />
<EnumDetails canonicalReference="@apollo/client!NetworkStatus:enum" headingLevel={3} />
<InterfaceDetails canonicalReference="@apollo/client/utilities/internal!DocumentationTypes.ApolloQueryResult:interface" headingLevel={3} />