Skip to content

Commit

Permalink
fix(flutter): return callback results in case of futures to await
Browse files Browse the repository at this point in the history
  • Loading branch information
micimize committed Aug 30, 2019
1 parent 617dde7 commit c7d6fd1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
12 changes: 5 additions & 7 deletions packages/graphql/lib/src/core/observable_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -227,18 +227,16 @@ class ObservableQuery {
callbacks ??= const <OnData>[];
StreamSubscription<QueryResult> subscription;

subscription = stream.listen((QueryResult result) {
void handle(OnData callback) {
callback(result);
}

subscription = stream.listen((QueryResult result) async {
if (!result.loading) {
callbacks.forEach(handle);
for (final callback in callbacks) {
await callback(result);
}

queryManager.rebroadcastQueries();

if (!result.optimistic) {
subscription.cancel();
await subscription.cancel();
_onDataSubscriptions.remove(subscription);

if (_onDataSubscriptions.isEmpty) {
Expand Down
4 changes: 2 additions & 2 deletions packages/graphql_flutter/lib/src/widgets/mutation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class MutationState extends State<Mutation> {
if (widget.onCompleted != null) {
return (QueryResult result) {
if (!result.loading && !result.optimistic) {
widget.onCompleted(result.data);
return widget.onCompleted(result.data);
}
};
}
Expand Down Expand Up @@ -122,7 +122,7 @@ class MutationState extends State<Mutation> {
if (result.optimistic) {
return optimisticUpdate(result);
} else {
widgetUpdate(cache, result);
return widgetUpdate(cache, result);
}
}

Expand Down

0 comments on commit c7d6fd1

Please sign in to comment.