watch

fun <D : Query.Data> ApolloCall<D>.watch(): Flow<ApolloResponse<D>>

Gets initial response(s) then observes the cache for any changes.

The cache subscription is established before the last initial response is collected, so any external cache update made after collecting it will be received.

Note: when using writeToCacheAsynchronously, the cache updates are postponed until after the response they come from has been emitted. They do not trigger an emission of their own: the data they store has already been emitted. Cache updates made anywhere else still do.

fetchPolicy controls how the result is first queried (default: FetchPolicy.CacheFirst), while refetchPolicy will control the subsequent fetches (default: FetchPolicy.CacheOnly).

Note: when manually updating the cache through ApolloStore, ApolloStore.publish must be called for watchers to be notified.

See also


fun <D : Query.Data> ApolloCall<D>.watch(data: D?): Flow<ApolloResponse<D>>

Observes the cache for the given data. Unlike the version of watch that takes no argument, no initial request is executed on the network. The fetch policy set by fetchPolicy will be used.