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.

Example

Signature

TypeScript
1result(): Promise<ApolloQueryResult<MaybeMasked<TData>>>

Result

Promise<ApolloQueryResult<MaybeMasked<TData>>>
Show/hide child attributes
Other
MaybeMasked<TData>
ApolloError

The 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.

boolean
NetworkStatus

Example

Signature

TypeScript
1getCurrentResult(
2  saveAsLastResult?: boolean
3): ApolloQueryResult<MaybeMasked<TData>>

Parameters

Name / Type
Description

Result

ApolloQueryResult<MaybeMasked<TData>>
Show/hide child attributes
Other
MaybeMasked<TData>
ApolloError

The 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.

boolean
NetworkStatus

Update the variables of this observable query, and fetch the new results. This method should be preferred over setVariables in most use cases.

Signature

TypeScript
1refetch(
2  variables?: Partial<TVariables>
3): Promise<ApolloQueryResult<MaybeMasked<TData>>>

Parameters

Name / Type
Description
variables (optional)Partial<TVariables>

The new set of variables. If there are missing variables, the previous values of those variables will be used.

Result

Promise<ApolloQueryResult<MaybeMasked<TData>>>
Show/hide child attributes
Other
MaybeMasked<TData>
ApolloError

The 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.

boolean
NetworkStatus

Example

Signature

TypeScript
1setOptions(
2  newOptions: Partial<WatchQueryOptions<TVariables, TData>>
3): Promise<ApolloQueryResult<MaybeMasked<TData>>>

Parameters

Name / Type
Description
newOptionsPartial<WatchQueryOptions<TVariables, TData>>

Result

Promise<ApolloQueryResult<MaybeMasked<TData>>>
Show/hide child attributes
Other
MaybeMasked<TData>
ApolloError

The 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.

boolean
NetworkStatus

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

TypeScript
1setVariables(
2  variables: TVariables
3): Promise<ApolloQueryResult<MaybeMasked<TData>> | void>

Parameters

Name / Type
Description
variablesTVariables

The new set of variables. If there are missing variables, the previous values of those variables will be used.

Result

Promise<ApolloQueryResult<MaybeMasked<TData>> | void>
Show/hide child attributes
Other
MaybeMasked<TData>
ApolloError

The 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.

boolean
NetworkStatus

A function that helps you fetch the next set of results for a paginated list field.

Signature

TypeScript
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<ApolloQueryResult<MaybeMasked<TFetchData>>>

Parameters

Name / Type
Description
fetchMoreOptionsFetchMoreQueryOptions<TFetchVars, TFetchData> & { updateQuery?: (previousQueryResult: Unmasked<TData>, options: { fetchMoreResult: Unmasked<TFetchData>; variables: TFetchVars; }) => Unmasked<TData>; }

Result

Promise<ApolloQueryResult<MaybeMasked<TFetchData>>>
Show/hide child attributes
Other
MaybeMasked<TFetchData>
ApolloError

The 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.

boolean
NetworkStatus

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

TypeScript
1updateQuery<TVars>(
2  mapFn: (previousQueryResult: Unmasked<TData>, options: Pick<WatchQueryOptions<TVars, TData>, "variables">) => Unmasked<TData>
3): void

Parameters

Name / Type
Description
mapFn(previousQueryResult: Unmasked<TData>, options: Pick<WatchQueryOptions<TVars, TData>, "variables">) => Unmasked<TData>

A function that instructs the query to begin re-executing at a specified interval (in milliseconds).

Signature

TypeScript
1startPolling(
2  pollInterval: number
3): void

Parameters

Name / Type
Description

A function that instructs the query to stop polling after a previous call to startPolling.

Signature

TypeScript
1stopPolling(): void

A 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

TypeScript
1subscribeToMore<TSubscriptionData, TSubscriptionVariables>(
2  options: SubscribeToMoreOptions<TData, TSubscriptionVariables, TSubscriptionData>
3): () => void

Parameters

Name / Type
Description
optionsSubscribeToMoreOptions<TData, TSubscriptionVariables, TSubscriptionData>

Result

() => void

Types

The current status of a query’s execution in our system.

Enumeration Members

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.

Properties
Name / Type
Description
Other
ApolloError

The 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.

boolean
NetworkStatus
Feedback

Edit on GitHub

Forums