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
1result(): Promise<ApolloQueryResult<TData>>
Result
Promise<ApolloQueryResult<TData>>
Show/hide child attributes
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
boolean
Example
Signature
1getCurrentResult(
2 saveAsLastResult?: boolean
3): ApolloQueryResult<TData>
Parameters
Result
ApolloQueryResult<TData>
Show/hide child attributes
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
boolean
Update 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<ApolloQueryResult<TData>>
Parameters
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<TData>>
Show/hide child attributes
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
boolean
Example
Signature
1setOptions(
2 newOptions: Partial<WatchQueryOptions<TVariables, TData>>
3): Promise<ApolloQueryResult<TData>>
Parameters
Result
Promise<ApolloQueryResult<TData>>
Show/hide child attributes
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
boolean
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<ApolloQueryResult<TData> | void>
Parameters
variables
TVariables
The new set of variables. If there are missing variables, the previous values of those variables will be used.
Result
Promise<ApolloQueryResult<TData> | void>
Show/hide child attributes
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
boolean
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: TData, options: {
4 fetchMoreResult: TFetchData;
5 variables: TFetchVars;
6 }) => TData;
7 }
8): Promise<ApolloQueryResult<TFetchData>>
Parameters
fetchMoreOptions
FetchMoreQueryOptions<TFetchVars, TFetchData> & {
updateQuery?: (previousQueryResult: TData, options: {
fetchMoreResult: TFetchData;
variables: TFetchVars;
}) => TData;
}
Result
Promise<ApolloQueryResult<TFetchData>>
Show/hide child attributes
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
boolean
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<TVars>(
2 mapFn: (previousQueryResult: TData, options: Pick<WatchQueryOptions<TVars, TData>, "variables">) => TData
3): void
Parameters
mapFn
(previousQueryResult: TData, options: Pick<WatchQueryOptions<TVars, TData>, "variables">) => TData
A function that instructs the query to begin re-executing at a specified interval (in milliseconds).
Signature
1startPolling(
2 pollInterval: number
3): void
Parameters
A function that instructs the query to stop polling after a previous call to startPolling
.
Signature
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
1subscribeToMore<TSubscriptionData, TSubscriptionVariables>(
2 options: SubscribeToMoreOptions<TData, TSubscriptionVariables, TSubscriptionData>
3): () => void
Parameters
options
SubscribeToMoreOptions<TData, TSubscriptionVariables, TSubscriptionData>
Result
() => void
Types
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.
T
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
boolean