Skip to content

Commit a58580d

Browse files
Merge pull request #1136 from kvenn/patch-2
Allow for providing a fetchPolicy to ObservableQuery.fetchResults
2 parents 62f1fcc + 81028b3 commit a58580d

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

packages/graphql/lib/src/core/observable_query.dart

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,18 @@ class ObservableQuery<TParsed> {
182182
}
183183
}
184184

185-
/// Fetch results based on [options.fetchPolicy]
185+
/// Fetch results based on [options.fetchPolicy] by default.
186+
///
187+
/// Optionally provide a [fetchPolicy] which will override the
188+
/// default [options.fetchPolicy], just for this request.
186189
///
187190
/// Will [startPolling] if [options.pollInterval] is set
188-
MultiSourceResult<TParsed> fetchResults() {
191+
MultiSourceResult<TParsed> fetchResults({FetchPolicy? fetchPolicy}) {
192+
final fetchOptions = fetchPolicy == null
193+
? options
194+
: options.copyWithFetchPolicy(fetchPolicy);
189195
final MultiSourceResult<TParsed> allResults =
190-
queryManager.fetchQueryAsMultiSourceResult(queryId, options);
196+
queryManager.fetchQueryAsMultiSourceResult(queryId, fetchOptions);
191197
latestResult ??= allResults.eagerResult;
192198

193199
if (allResults.networkResult == null) {
@@ -201,8 +207,9 @@ class ObservableQuery<TParsed> {
201207
: QueryLifecycle.pending;
202208
}
203209

204-
if (options.pollInterval != null && options.pollInterval! > Duration.zero) {
205-
startPolling(options.pollInterval);
210+
if (fetchOptions.pollInterval != null &&
211+
fetchOptions.pollInterval! > Duration.zero) {
212+
startPolling(fetchOptions.pollInterval);
206213
}
207214

208215
return allResults;

0 commit comments

Comments
 (0)