Skip to content

Commit

Permalink
fix: add eager result to stream, rebuild query widget on var change
Browse files Browse the repository at this point in the history
  • Loading branch information
micimize committed Aug 29, 2019
1 parent 5f938e4 commit af89b19
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions packages/graphql/lib/src/core/observable_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ class ObservableQuery {
void onListen() {
if (_latestWasEagerlyFetched) {
_latestWasEagerlyFetched = false;

// eager results are resolved synchronously,
// so we have to add them manually now that
// the stream is available
if (!controller.isClosed && latestResult != null) {
controller.add(latestResult);
}
return;
}
if (options.fetchResults) {
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql_flutter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ FetchMoreOptions opts = FetchMoreOptions(
];
// to avoid a lot of work, lets just update the list of repos in returned
// data with new data, this also ensure we have the endCursor already set
// data with new data, this also ensures we have the endCursor already set
// correctly
fetchMoreResultData['search']['nodes'] = repos;
Expand Down
1 change: 1 addition & 0 deletions packages/graphql_flutter/lib/src/widgets/query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class QueryState extends State<Query> {
@override
Widget build(BuildContext context) {
return StreamBuilder<QueryResult>(
key: Key(observableQuery?.options?.toKey()),
initialData: observableQuery?.latestResult ?? QueryResult(loading: true),
stream: observableQuery.stream,
builder: (
Expand Down

0 comments on commit af89b19

Please sign in to comment.