ObservableQuery
API reference
ObservableQuery functions
ApolloClient Observables extend the Observables implementation provided by zen-observable. Refer to the zen-observable documentation for additional context and API options.
⚠️ Deprecated
resultwill be removed in Apollo Client 4.0.Recommended now
If you continue to need this functionality, subscribe to
ObservableQueryto get the first value emitted from the observable, then immediately unsubscribe.When upgrading
Use RxJS's
firstResultFromfunction to mimic this functionality.TypeScript1const result = await firstValueFrom(from(observableQuery));
Signature
1result(): Promise<ApolloQueryResult<MaybeMasked<TData>>>Result
Promise<ApolloQueryResult<MaybeMasked<TData>>>Show/hide child attributes
MaybeMasked<TData>An object containing the result of your GraphQL query after it completes.
This value might be undefined if a query results in one or more errors (depending on the query's errorPolicy).
ApolloErrorThe single Error object that is passed to onError and useQuery hooks, and is often thrown during manual client.query calls. This will contain both a NetworkError field and any GraphQLErrors. See https://www.apollographql.com/docs/react/data/error-handling/ for more information.
ReadonlyArray<GraphQLFormattedError>A list of any errors that occurred during server-side execution of a GraphQL operation. See https://www.apollographql.com/docs/react/data/error-handling/ for more information.
booleanNetworkStatusbooleanSignature
1getCurrentResult(
2 saveAsLastResult?: boolean
3): ApolloQueryResult<MaybeMasked<TData>>Parameters
Result
ApolloQueryResult<MaybeMasked<TData>>Show/hide child attributes
MaybeMasked<TData>An object containing the result of your GraphQL query after it completes.
This value might be undefined if a query results in one or more errors (depending on the query's errorPolicy).
ApolloErrorThe single Error object that is passed to onError and useQuery hooks, and is often thrown during manual client.query calls. This will contain both a NetworkError field and any GraphQLErrors. See https://www.apollographql.com/docs/react/data/error-handling/ for more information.
ReadonlyArray<GraphQLFormattedError>A list of any errors that occurred during server-side execution of a GraphQL operation. See https://www.apollographql.com/docs/react/data/error-handling/ for more information.
booleanNetworkStatusbooleanUpdate the variables of this observable query, and fetch the new results. This method should be preferred over setVariables in most use cases.
Signature
1refetch(
2 variables?: Partial<TVariables>
3): Promise<InteropApolloQueryResult<MaybeMasked<TData>>>Parameters
The new set of variables. If there are missing variables, the previous values of those variables will be used.
Result
Promise<InteropApolloQueryResult<MaybeMasked<TData>>>Show/hide child attributes
MaybeMasked<TData>An object containing the result of your GraphQL query after it completes.
This value might be undefined if a query results in one or more errors (depending on the query's errorPolicy).
ApolloErrorThe single Error object that is passed to onError and useQuery hooks, and is often thrown during manual client.query calls. This will contain both a NetworkError field and any GraphQLErrors. See https://www.apollographql.com/docs/react/data/error-handling/ for more information.
ReadonlyArray<GraphQLFormattedError>⚠️ Deprecated
errorswill no longer available on the result in Apollo Client 4.0. This value is safe to use in Apollo Client 3.x.Recommended now
No action needed
When upgrading
errorshas been consolidated to theerrorproperty. You will need to read any errors on theerrorproperty on the resolved value instead.
boolean⚠️ Deprecated
loadingwill no longer available on the result in Apollo Client 4.0. This value is always true when the resolved and can safely ignored.
NetworkStatus⚠️ Deprecated
loadingwill no longer available on the result in Apollo Client 4.0. This value is alwaysNetworkStatus.readyorNetworkStatus.error. To determine if the result contains an error, read from theerrororerrorsproperty instead.
boolean⚠️ Deprecated
partialwill no longer available on the result in Apollo Client 4.0. This value is alwaysfalseif there is a data value since the result never contains partial cache data.
⚠️ Deprecated
setOptionswill be removed in Apollo Client 4.0. Please useobservableQuery.reobserve(newOptions)instead.
Signature
1setOptions(
2 newOptions: Partial<WatchQueryOptions<TVariables, TData>>
3): Promise<InteropApolloQueryResult<MaybeMasked<TData>>>Parameters
Result
Promise<InteropApolloQueryResult<MaybeMasked<TData>>>Show/hide child attributes
MaybeMasked<TData>An object containing the result of your GraphQL query after it completes.
This value might be undefined if a query results in one or more errors (depending on the query's errorPolicy).
ApolloErrorThe single Error object that is passed to onError and useQuery hooks, and is often thrown during manual client.query calls. This will contain both a NetworkError field and any GraphQLErrors. See https://www.apollographql.com/docs/react/data/error-handling/ for more information.
ReadonlyArray<GraphQLFormattedError>⚠️ Deprecated
errorswill no longer available on the result in Apollo Client 4.0. This value is safe to use in Apollo Client 3.x.Recommended now
No action needed
When upgrading
errorshas been consolidated to theerrorproperty. You will need to read any errors on theerrorproperty on the resolved value instead.
boolean⚠️ Deprecated
loadingwill no longer available on the result in Apollo Client 4.0. This value is always true when the resolved and can safely ignored.
NetworkStatus⚠️ Deprecated
loadingwill no longer available on the result in Apollo Client 4.0. This value is alwaysNetworkStatus.readyorNetworkStatus.error. To determine if the result contains an error, read from theerrororerrorsproperty instead.
boolean⚠️ Deprecated
partialwill no longer available on the result in Apollo Client 4.0. This value is alwaysfalseif there is a data value since the result never contains partial cache data.
Update the variables of this observable query, and fetch the new results if they've changed. Most users should prefer refetch instead of setVariables in order to to be properly notified of results even when they come from the cache.
Note: the next callback will not fire if the variables have not changed or if the result is coming from cache.
Note: the promise will return the old results immediately if the variables have not changed.
Note: the promise will return null immediately if the query is not active (there are no subscribers).
Signature
1setVariables(
2 variables: TVariables
3): Promise<InteropApolloQueryResult<MaybeMasked<TData>> | void>Parameters
The new set of variables. If there are missing variables, the previous values of those variables will be used.
Result
Promise<InteropApolloQueryResult<MaybeMasked<TData>> | void>Show/hide child attributes
MaybeMasked<TData>An object containing the result of your GraphQL query after it completes.
This value might be undefined if a query results in one or more errors (depending on the query's errorPolicy).
ApolloErrorThe single Error object that is passed to onError and useQuery hooks, and is often thrown during manual client.query calls. This will contain both a NetworkError field and any GraphQLErrors. See https://www.apollographql.com/docs/react/data/error-handling/ for more information.
ReadonlyArray<GraphQLFormattedError>⚠️ Deprecated
errorswill no longer available on the result in Apollo Client 4.0. This value is safe to use in Apollo Client 3.x.Recommended now
No action needed
When upgrading
errorshas been consolidated to theerrorproperty. You will need to read any errors on theerrorproperty on the resolved value instead.
boolean⚠️ Deprecated
loadingwill no longer available on the result in Apollo Client 4.0. This value is always true when the resolved and can safely ignored.
NetworkStatus⚠️ Deprecated
loadingwill no longer available on the result in Apollo Client 4.0. This value is alwaysNetworkStatus.readyorNetworkStatus.error. To determine if the result contains an error, read from theerrororerrorsproperty instead.
boolean⚠️ Deprecated
partialwill no longer available on the result in Apollo Client 4.0. This value is alwaysfalseif there is a data value since the result never contains partial cache data.
A function that helps you fetch the next set of results for a paginated list field.
Signature
1fetchMore<TFetchData, TFetchVars>(
2 fetchMoreOptions: FetchMoreQueryOptions<TFetchVars, TFetchData> & {
3 updateQuery?: (previousQueryResult: Unmasked<TData>, options: {
4 fetchMoreResult: Unmasked<TFetchData>;
5 variables: TFetchVars;
6 }) => Unmasked<TData>;
7 }
8): Promise<InteropApolloQueryResult<MaybeMasked<TFetchData>>>Parameters
fetchMoreOptionsFetchMoreQueryOptions<TFetchVars, TFetchData> & {
updateQuery?: (previousQueryResult: Unmasked<TData>, options: {
fetchMoreResult: Unmasked<TFetchData>;
variables: TFetchVars;
}) => Unmasked<TData>;
}Result
Promise<InteropApolloQueryResult<MaybeMasked<TFetchData>>>Show/hide child attributes
MaybeMasked<TFetchData>An object containing the result of your GraphQL query after it completes.
This value might be undefined if a query results in one or more errors (depending on the query's errorPolicy).
ApolloErrorThe single Error object that is passed to onError and useQuery hooks, and is often thrown during manual client.query calls. This will contain both a NetworkError field and any GraphQLErrors. See https://www.apollographql.com/docs/react/data/error-handling/ for more information.
ReadonlyArray<GraphQLFormattedError>⚠️ Deprecated
errorswill no longer available on the result in Apollo Client 4.0. This value is safe to use in Apollo Client 3.x.Recommended now
No action needed
When upgrading
errorshas been consolidated to theerrorproperty. You will need to read any errors on theerrorproperty on the resolved value instead.
boolean⚠️ Deprecated
loadingwill no longer available on the result in Apollo Client 4.0. This value is always true when the resolved and can safely ignored.
NetworkStatus⚠️ Deprecated
loadingwill no longer available on the result in Apollo Client 4.0. This value is alwaysNetworkStatus.readyorNetworkStatus.error. To determine if the result contains an error, read from theerrororerrorsproperty instead.
boolean⚠️ Deprecated
partialwill no longer available on the result in Apollo Client 4.0. This value is alwaysfalseif there is a data value since the result never contains partial cache data.
A function that enables you to update the query's cached result without executing a followup GraphQL operation.
See using updateQuery and updateFragment for additional information.
Signature
1updateQuery(
2 mapFn: UpdateQueryMapFn<TData, TVariables>
3): voidParameters
A function that instructs the query to begin re-executing at a specified interval (in milliseconds).
Signature
1startPolling(
2 pollInterval: number
3): voidParameters
A function that instructs the query to stop polling after a previous call to startPolling.
Signature
1stopPolling(): voidA function that enables you to execute a subscription, usually to subscribe to specific fields that were included in the query.
This function returns another function that you can call to terminate the subscription.
Signature
1subscribeToMore<TSubscriptionData, TSubscriptionVariables>(
2 options: SubscribeToMoreOptions<TData, TSubscriptionVariables, TSubscriptionData, TVariables>
3): () => voidParameters
Result
() => voidTypes
The current status of a query’s execution in our system.
No request is in flight for this query, but one or more errors were detected.
Indicates that fetchMore was called on this query and that the query created is currently in flight.
The query has never been run before and the query is now currently running. A query will still have this network status even if a partial data result was returned from the cache, but a query was dispatched anyway.
Indicates that a polling query is currently in flight. So for example if you are polling a query every 10 seconds then the network status will switch to poll every 10 seconds whenever a poll request has been sent but not resolved.
No request is in flight for this query, and no errors happened. Everything is OK.
Similar to the setVariables network status. It means that refetch was called on a query and the refetch request is currently in flight.
If setVariables was called and a query was fired because of that then the network status will be setVariables until the result of that query comes back.
TAn object containing the result of your GraphQL query after it completes.
This value might be undefined if a query results in one or more errors (depending on the query's errorPolicy).
ApolloErrorThe single Error object that is passed to onError and useQuery hooks, and is often thrown during manual client.query calls. This will contain both a NetworkError field and any GraphQLErrors. See https://www.apollographql.com/docs/react/data/error-handling/ for more information.
ReadonlyArray<GraphQLFormattedError>A list of any errors that occurred during server-side execution of a GraphQL operation. See https://www.apollographql.com/docs/react/data/error-handling/ for more information.
booleanNetworkStatusboolean