ObservableQuery<TParsed> class
Null safety
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> > -
read / write
- hashCode → int
-
The hash code for this object. [...]
read-only, inherited
- isCurrentlyPolling → bool
-
read-only
- isRebroadcastSafe → bool
-
Whether it is safe to rebroadcast results due to cache
changes based on policies and lifecycle. [...]
read-only
- isRefetchSafe → bool
-
read-only
-
latestResult
↔ QueryResult<
TParsed> ? -
The most recently seen result from this operation's stream
read / write
- lifecycle ↔ QueryLifecycle
-
read / write
- optimisticResult ← Object?
-
write-only
-
options
↔ WatchQueryOptions<
TParsed> -
read / write
- queryId → String
-
The identity of this query within the QueryManager
final
- queryManager → QueryManager
-
@protected, final
- runtimeType → Type
-
A representation of the runtime type of the object.
read-only, inherited
- scheduler → QueryScheduler?
-
@protected, read-only
- sideEffectsArePending → bool
-
onData callbacks have het to be run [...]
read-only
-
stream
→ Stream<
QueryResult< TParsed> > -
read-only
-
variables
← Map<
String, dynamic> -
write-only
Methods
-
addResult(
QueryResult< TParsed> result, {bool fromRebroadcast = false}) → void -
Add a
result
to the stream unless it was created beforelasestResult
. [...] -
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(
) → MultiSourceResult< TParsed> -
Fetch results based on
options.fetchPolicy
[...] -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a non-existent method or property is accessed. [...]
inherited
-
onData(
Iterable< OnData< callbacks) → voidTParsed> > -
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