zino-hofmann / graphql-flutter

A GraphQL client for Flutter, bringing all the features from a modern GraphQL client to one easy to use package.
https://zino-hofmann.github.io/graphql-flutter
MIT License
3.25k stars 620 forks source link

Allow for providing a fetchPolicy to ObservableQuery.fetchResults #1136

Closed kvenn closed 2 years ago

kvenn commented 2 years ago

Fixes / Enhancements

Added the ability to provide a fetchPolicy to ObservableQuery.fetchResults

Use case

I'll usually hook up an observable with the fetchResults parameter set to false and then periodically call fetchResults on it.

ObservableQuery observableQuery =  client.watchQuery(
      WatchQueryOptions(
        fetchPolicy: fetchPolicy,
        // Tells the watch not to fetch right away. Trigger with `fetchResults`
        fetchResults: false,
        variables: options.variables,
        document: options.document,
      ),
    );

observableQuery.fetchResults();

But on subsequent calls to fetchResults, I might want to tell it to fetch from network only, cache only, etc. A concrete example being that I'd like to initialize this observable to start with a fetchPolicy of onlyCache. Then when the user pulls to refresh, I'd like to trigger fetchResults(networkOnly).

Currently, I'd need to initialize a new observable or use a new async / await call, even though my listener would be the same.

I also might be misusing the library, so please let me know if this makes sense!

vincenzopalazzo commented 2 years ago

Before starting the review, can you take at look the CI failure? thanks!

vincenzopalazzo commented 2 years ago

@budde377 do you have any concerns about these PRs? we can merge it? with the merge we should be have fixed also the test coverage