New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Query refetch not working #346
Comments
I haven't had this problem. It would be useful if you could provide a better reproduction. Try to base it on the example of this project and maybe one would help. |
This is sample of my code where I am using a refetch()
|
I have been following the documentation but it isnt working for me. That is a portion of my code where I used the refetch(). Everything else is working except that |
I'm also experiencing a similar issue. I'm trying to use refetch with the |
@lucasavila00 can you add here the snippet that works for you? |
My best guess is that there's some issue with the observable query Also, if you're results get populated from the cache first, maybe it'll work after the first network request completes. Also, format your code snippets. And I assume you meant this in your first example return FloatingActionButton(
- onPressed: refetch(),
+ onPressed: refetch,
tooltip: 'Increment',
child: Icon(Icons.add),
) This is the refetch code in bool get _isRefetchSafe {
switch (lifecycle) {
case QueryLifecycle.COMPLETED:
case QueryLifecycle.POLLING:
case QueryLifecycle.POLLING_STOPPED:
return true;
case QueryLifecycle.PENDING:
case QueryLifecycle.CLOSED:
case QueryLifecycle.UNEXECUTED:
case QueryLifecycle.SIDE_EFFECTS_PENDING:
case QueryLifecycle.SIDE_EFFECTS_BLOCKING:
return false;
}
return false;
}
/// Attempts to refetch, returning `true` if successful
bool refetch() {
if (_isRefetchSafe) {
queryManager.refetchQuery(queryId);
return true;
}
return false;
} |
I didn't provide any fetchPolicy in my code. So I guess I am using the default |
@micimize I debugged my code here, and could state that my query lifecicle is |
Even when my |
@JeffersonCarvalh0 to clarify, you:
If so, this is likely a regression |
Exactly. The query that is performed when the widget is built works perfectly. The problem only happens when I try to refetch. |
@JeffersonCarvalh0 I needed to be able to refetch so I found a hack around pollInterval. I initially set pollInterval to null so when the person clicks on the button to refetch I call setState to change pollInterval to say 2. So after the request is successful I call setState again to change pollInterval to null . It is not the best of idea but for now don't have any option |
Thanks, @Wisdom0063, it worked like a charm here! |
@mainawycliffe this is still a problem. Why did you close the issue? Do we have a PR fixing it? What they guys did was just a workaround. |
@guilhermedecampo I am sorry. Thought it was resolved, judging by the last comment. I am reopening it, will look in to it over the week. Can you reproduce the issue on a small repo, may be using the GitHub API? |
@mainawycliffe any directions for this? like @Wisdom0063 said, lifecycle is always pending so refetch is always unsafe. If you are too busy, just point me to right direction and I'll try to find the root cause. |
@serendipity1004 this completely slipped under my radar, I am sorry about that. I will look into it in the course of the week and share my thoughts on the way forward. |
amazing @mainawycliffe |
@serendipity1004 I can't still reproduce this error with the examples we have, though I am using the latest version which is yet to release. |
A repo reproducing the issue would be very useful, this way I can jump right in to debug the issue. |
For me, it's working with the latest beta. |
If anyone still has this issue on |
I just ran into a related problem, I think. I have a watch query which uses I suspect the root cause is in the order of the call to MultiSourceResult fetchResults() {
final MultiSourceResult allResults =
queryManager.fetchQueryAsMultiSourceResult(queryId, options);
latestResult ??= allResults.eagerResult;
// if onData callbacks have been registered,
// they are waited on by default
lifecycle = _onDataCallbacks.isNotEmpty
? QueryLifecycle.sideEffectsPending
: QueryLifecycle.pending;
if (options.pollInterval != null && options.pollInterval > Duration.zero) {
startPolling(options.pollInterval);
}
return allResults;
} |
@blaugold I'd consider this a different issue, but based on what you're saying it seems unlikely to me that you need to refetch. Any changes to the underlying data in the cache will trigger a rebroadcast on the observable query automatically, Might be a bit different on |
@micimize Thanks for all the work on this package. I would like to use only the cache if the data is available and let the user trigger a refresh from the server whenever they want to. I thought that was possible with a combination of |
The text was updated successfully, but these errors were encountered: