Closed Jaew00Shin closed 3 months ago
Just so I understand: Why do you need to await refetching the queries after a mutation? Are you running code after that requires the certain queries to be refetched first?
I think the mutation should complete once the mutation is finished as the "refetch" part is a side effect and not actually part of the mutation. However, like you say, the refetchQueries
function could return a future so you could manually await it yourself. Invalidate queries is not asynchronous so it wouldn't make any sense to turn that into a future. That just sets the query to stale so that the next time it is displayed it is refetched (useful for off screen queries).
For now you could use CachedQuery.instance.whereQuery
or CachedQuery.instance.getQuery
to manually do your request:
Future<void> doMutation() async {
final result = await _googleLogInMutation.mutate();
final otherQuery = CachedQuery.instance.getQuery(otherQueryKey);
await otherQuery?.refetch();
// some code that relies on the refetch
}
for example, above code is my mutation for signing in with google. The goal I want is that when mutate of mutation is finished, refetching & invalidating queries should be done.
But now code is
Future<State> refetch();
Although method refetch in query_base.dart return future, refetchQueries in cached_query.dart return void.
So, Could you change return type of refetchQuries in cached_query.dart from void to Future. ?
I suggest the below code
This code is just example. It may not works well. But I suggest that refetchiQueries should return Future and it should have await keyword when used in _fetch method of mutation.dart.
I want to be applied this for refetchQueries as well as invalidateQueries.
The ultimate goal is that it should be insuranced refetching queries are already refetched & invalidateQueries are already invalidated after mutation is done.