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.24k stars 614 forks source link

How to use poll_interval with the standalone graphl client package? #498

Closed RanaOsamaAsif closed 4 years ago

RanaOsamaAsif commented 4 years ago

I need some help in understanding how to use the poll_interval with the standalone graphql package. Not with graphql_flutter which provides Query and Mutation widgets.

I tried the flutter flutter_bloc example which apparently uses the poll_interval parameter in WatchQueryOptions but it does not execute the query again after the interval maybe because it's in a function.

Future<QueryResult> getRepositories(int numOfRepositories) async { final WatchQueryOptions _options = WatchQueryOptions( document: readRepositories, variables: <String, dynamic>{ 'nRepositories': numOfRepositories, }, pollInterval: 4, fetchResults: true, ); return await client.query(_options); }

How can I use the polling feature from the graphql package in a function as given in the example? Any help would be great.

mainawycliffe commented 4 years ago

For pollInterval to work, instead of using _client.query, I think you have to use _client.watchQuery instead. That will add the query to the schedule for polling at a set interval.