ObservableQuery<TParsed> class

An Observable/Stream-based API for both queries and mutations.

Returned from GraphQLClient.watchQuery for use in reactive programming, for instance in graphql_flutter widgets. It is modelled closely after Apollo's ObservableQuery

ObservableQuery's core api/usage is to fetchResults, then listen to the stream. fetchResults will be called on instantiation if options.eagerlyFetchResults is set, which in turn defaults to options.fetchResults.

Beyond that, ObservableQuery is a bit of a kitchen sink:

  • There are refetch and fetchMore methods for fetching more results
  • An onData method for registering callbacks (namely for mutations)
  • lifecycle for tracking polling, side effect, an inflight execution state
  • latestResult – the most recent result from this operation

And a handful of internally leveraged methods.

Constructors

ObservableQuery({required QueryManager queryManager, required WatchQueryOptions<TParsed> options})

Properties

controller StreamController<QueryResult<TParsed>>
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
isCurrentlyPolling bool
no setter
isRebroadcastSafe bool
Whether it is safe to rebroadcast results due to cache changes based on policies and lifecycle.
no setter
isRefetchSafe bool
no setter
latestResult QueryResult<TParsed>?
The most recently seen result from this operation's stream
getter/setter pair
lifecycle QueryLifecycle
getter/setter pair
optimisticResult Object?
no getter
options WatchQueryOptions<TParsed>
getter/setter pair
queryId String
The identity of this query within the QueryManager
final
queryManager QueryManager
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
scheduler → QueryScheduler?
no setter
sideEffectsArePending bool
onData callbacks have het to be run
no setter
stream Stream<QueryResult<TParsed>>
no setter
variables Map<String, dynamic>
no getter

Methods

addResult(QueryResult<TParsed> result, {bool fromRebroadcast = false}) → void
Add a result to the stream unless it was created before lasestResult.
close({bool force = false, bool fromManager = false}) FutureOr<QueryLifecycle>
Closes the query or mutation, or else queues it for closing.
fetchMore(FetchMoreOptions fetchMoreOptions) Future<QueryResult<TParsed>>
fetch more results and then merge them with the latestResult according to FetchMoreOptions.updateQuery.
fetchResults({FetchPolicy? fetchPolicy}) MultiSourceResult<TParsed>
Fetch results based on options.fetchPolicy by default.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onData(Iterable<OnData<TParsed>> callbacks, {bool removeAfterInvocation = true}) → void Function()
Register callbacks to trigger when stream has new results where QueryResult.isNotLoading
onListen() → void
refetch() Future<QueryResult<TParsed>?>
Attempts to refetch on the network, throwing error if not refetch safe
startPolling(Duration? pollInterval) → void
Poll the server periodically for results.
stopPolling() → void
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited