fetchResults method

MultiSourceResult<TParsed> fetchResults({
  1. FetchPolicy? fetchPolicy,
})

Fetch results based on options.fetchPolicy by default.

Optionally provide a fetchPolicy which will override the default options.fetchPolicy, just for this request.

Will startPolling if options.pollInterval is set

Implementation

MultiSourceResult<TParsed> fetchResults({FetchPolicy? fetchPolicy}) {
  final fetchOptions = fetchPolicy == null
      ? options
      : options.copyWithFetchPolicy(fetchPolicy);
  final MultiSourceResult<TParsed> allResults =
      queryManager.fetchQueryAsMultiSourceResult(queryId, fetchOptions);
  latestResult ??= allResults.eagerResult;

  if (allResults.networkResult == null) {
    // This path is only possible for cacheFirst and cacheOnly fetch policies.
    lifecycle = QueryLifecycle.completed;
  } else {
    // if onData callbacks have been registered,
    // they are waited on by default
    lifecycle = _onDataCallbacks.isNotEmpty
        ? QueryLifecycle.sideEffectsPending
        : QueryLifecycle.pending;
  }

  if (fetchOptions.pollInterval != null &&
      fetchOptions.pollInterval! > Duration.zero) {
    startPolling(fetchOptions.pollInterval);
  }

  return allResults;
}