-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
skip in useQuery hook doesn't work as expected #6190
Comments
I get the same bug. |
I also get the same issue with |
It's failing for me as well |
skip seem to be broken in apollo-client version 3. using ^3.0.0-beta.50 |
+1 |
seems still broken in |
I'm using Use cases:
Small runnable reproduction:https://codesandbox.io/s/skip-does-not-work-rx2rj?file=/src/App.js I have an array of currencies, and I only want to fetch the currencies which indexes are odd. ExpectedOnly queries for odd indexes should trigger an HTTP request. ActualAfter setting the variable to ScreenshotsRunning USD is even, so it skips, and Unfortunately, Apollo triggers an HTTP request anyway, independent of The only one it respects is the first time I pass |
As a work-around, I'm using |
Still having this issue (truthy skip values are ignored) with final version 3.0.0 But I was able to bisect it, maybe that helps the AC contributors (@benjamn @hwillson): 9793b7d9159fae3e82f989be3db6d923fd811893 is the first bad commit
commit 9793b7d9159fae3e82f989be3db6d923fd811893
Author: Ben Newman <[email protected]>
Date: Thu Apr 30 12:04:17 2020 -0400
Refactor ObservableQuery#reobserve to use Reobserver class.
src/core/ObservableQuery.ts | 198 +++++++++-----------------------------------
src/core/QueryManager.ts | 55 ++++++------
src/core/Reobserver.ts | 142 +++++++++++++++++++++++++++++++
3 files changed, 208 insertions(+), 187 deletions(-)
create mode 100644 src/core/Reobserver.ts Bisect range was from tag v3.0.0-beta.45 (good) till tag v3.0.0-beta.46 (bad): git bisect start
# bad: [884b1e5ac35ccad7c8c7778eeaf1f0d7ad40699a] Bump @apollo/client npm version to 3.0.0-beta.46.
git bisect bad 884b1e5ac35ccad7c8c7778eeaf1f0d7ad40699a
# good: [5bd74df074ccd1ec9273e3f4464db0e195e95af2] Bump @apollo/client npm version to 3.0.0-beta.45.
git bisect good 5bd74df074ccd1ec9273e3f4464db0e195e95af2
# bad: [9793b7d9159fae3e82f989be3db6d923fd811893] Refactor ObservableQuery#reobserve to use Reobserver class.
git bisect bad 9793b7d9159fae3e82f989be3db6d923fd811893
# good: [570cb66f9be66407c72a69dbc1ae415d9acb1a3d] Improve Concast comments.
git bisect good 570cb66f9be66407c72a69dbc1ae415d9acb1a3d
# good: [ae3f6d5a5e055aa17e705b8a25d8972f05b19a85] Go back to using a fresh query ID for fetchMore requests.
git bisect good ae3f6d5a5e055aa17e705b8a25d8972f05b19a85
# good: [8aeeba47199ffa49d32107f5a3a0d1f7c0a15e43] Allow in-flight fetchQueryObservable fetches to be cancelled.
git bisect good 8aeeba47199ffa49d32107f5a3a0d1f7c0a15e43
# good: [23b9d07f4f7127a4d2f5d5af2a457bbc841dfd04] Make Concast#{add,remove}Observer public, and allow quiet removal.
git bisect good 23b9d07f4f7127a4d2f5d5af2a457bbc841dfd04
# good: [6acaa370c819eab6e81d524923911bcf7fa4e2b7] Move polling logic from QueryManager to ObservableQuery.
git bisect good 6acaa370c819eab6e81d524923911bcf7fa4e2b7
# first bad commit: [9793b7d9159fae3e82f989be3db6d923fd811893] Refactor ObservableQuery#reobserve to use Reobserver class. |
If it is the exactly the same problem the fix is already merged and will come in the next release: |
@sapkra Thanks for mentioning it! |
This should now be fixed in |
Unfortunately, this still happens for me with 3.0.1 (fetchPolicy "network-only", skip: true) |
@hwillson I believe this bug is about stopping the actual request, whereas it appears your fix only changes the behavior of |
Yep, still broken @hwillson. |
Nevermind, "cache-only" did the trick ;-) |
I'm using a similar work-around (using |
@hwillson - still seeing this as an issue in |
@hwillson Yes, please re-open this. |
Hi @hwillson! This problem appears in my projects too, please re-open this issue. |
This is happening for us as well using 3.0.2. |
Still the case with |
Hey all 👋 ! It seems there has been quite a few comments about this issue since it was initially closed. I'm going to go ahead and reopen since judging by its comments, it seems that an issue still persists. I'm hoping we can dig into this a bit further very soon. Thanks for your patience! |
From what I can find, this issue appears to be fixed from I'm inclined to say this has been addressed by #9823, however I need some help getting a reproduction and/or failing test to demonstrate the continued buggy behavior. I've created a branch with some additional tests around the |
+1. Ran into this issue today. As a work around, I added a $skip variable to my query and used the |
I am still finding this to be an issue, have upgraded to 3.7.9 |
This is really strange... Yesterday this issue re-appeared. But today it works again, and I didn't change anything in my code. I'm on version:
I didn't change anything in my query code, but did some changes around url parameter parsing, maybe affecting how the component is rendered and how many times the component is rendered 🤔. Note that I'm using graphql-codegen to generate apollo helpers. (not the newest version)
|
Possibly related to this, I can confirm I'm seeing something similar on I noticed on I was about to make a Code Sandbox and open an issue, but then I saw this, and thought I'd post my findings here before opening a potential duplicate. EDIT: Upon further testing it appears the |
@AaronWatson2975 interestingly, in my mind, I would expect that Unfortunately our docs are a bit ambiguous, so its left up to interpretation. I'll see if we can make find a way to communicate the expected behavior for Regardless, I think we can all agree that at least the hook should behave properly, so if we are seeing fetches from the hook while @rwilliams3088 @thomastvedt @STGlancyPS if any of you could help create a reproduction with recent versions of Apollo, that would help tremendously. I'm afraid there isn't much we can do without one. I tried creating additional tests for everything I could think of, but I had no luck reproducing the issue. |
@jerelmiller thanks for the quick response. I had a feeling it might be intended behaviour but I wasn't sure, and I know it worked that way before Not sure if this helps with the original issue, but I made a 40 ish line CodeSandbox to reproduce my Here's the code if anyone else wants to play around with it (it was originally built to show the refetch issue, but if you check the network tab when it loads, you won't find network requests until the timer gets hit and refetch is called). So if you just remove the refetch code you'll notice there aren't any network requests (or that's what I saw when I ran it anyway). Hoping it might be helpful to someone trying to make an example to reproduce the original issue here. Thanks again! 🙏
|
Chiming in here to say still broken 3 years later. Version: 3.7.9 That's a long time to be asking your user base to implement their own hacky work arounds in order to use your package. |
Hi @kylewinkler 👋🏻 as @jerelmiller mentioned above, we're keen to fix this but haven't been able to reproduce the issue. Are you using the latest version of |
To add to this: the only reproduction (by buzinas above) we got for this is fixed (I just checked with our latest stable release, 3.7.10), so it's not like this had been around unsolved for three years. |
Sure, I will gather more information in a little bit. I understand that I haven't proven to you that it is the same bug but for the sake of all of our intelligence I will play it safe and incline myself to believe that exhibiting the same behavior as the previous comments and allowing the same workarounds, that this bug is still not fixed lol. But, time will tell. |
The problem still exists in Version 3.7.16. Even worse: I try skip the query in case the variable is not available. Due to the bug the query still fires leading to an error that the mandatory variable is not provided. As a result the
|
@tobiaswaltl could you please provide a reproduction of this that shows the problem? The only reproduction provided in this issue is fixed in recent versions - you might be encountering a similar problem, but we really need a reproduction for it. |
@phryneas I could narrow it a little bit down:
https://codesandbox.io/s/skip-does-not-work-forked-sdr7d2?file=/src/App.js |
As a workaround I tried to set the |
@tobiaswaltl Sorry for the late response. |
Hey all 👋 It's been a bit of time since the last reply on this issue. I'd like to give this one more chance at a reproduction before we close this. All signs on our end indicate this has been fixed in recent versions of the client. We've created a separate tracking issue for the bug reported in #6190 (comment) at #11120. I've got a branch setup with some additional tests that all pass with the various ways At this point, if you are still seeing this issue on recent versions of the client, we are going to require a runnable reproduction or failing test case that demonstrates this issue, otherwise we plan to close this as completed. Thanks! |
Hi, I'm not sure if I can give you a runnable reproduction or failing test case, but I came across this issue just now. In my case the skip is not honoured at all, even if it is set explicitly to true:
I am not an expert so I have no idea whether it's a user fault (me) or a problem with the package, but I'm happy to jump on a call on discord or wherever if you want to see. "node_modules/@vue/apollo-composable": { "node_modules/@apollo/client": { |
Hi @MrMossevig! |
Thank you! Anyways, the apollo-composable useQuery have the "enabled" option that I can use instead. Again, thank you and have a great day! |
Hey all 👋 We are going to go ahead and close this issue since it appears this has been resolved. If you do encounter a similar bug, please open a new issue with a reproduction and we'd be happy to assist. Thanks! |
Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better. |
Intended outcome:
I was trying to make request conditional, using "skip" in "useQuery" hook, here a brief code of that
here the second query GET_COURSE_BY_ID should be "skipped" if the bought is true,
that's well and good when logged in the console, I get courseDetails as undefined if bought is true,
but the thing is it actually makes the network request and sends back the requested data!!
here's what I get in the console
As expected 👍, courseDetails is undefined if bought is true, But as seen in the network tab it still actually makes a network request and return back the data for courseDetails it so happens that it just makes it undefined later;
The first request - for CHECK_COURSE_BOUGHT
The second request -for GET_COURSE_BY_ID
Actual outcome:
The network request should not be made!!, It should be "skipped" else what is the use of using it. if it is later on just reassigning the data to undefined.
How to reproduce the issue:
Just fallow the code above
Versions
System:
OS: Windows 10 10.0.18363
Binaries:
Node: 12.13.1 - C:\Program Files\nodejs\node.EXE
Yarn: 1.17.3 - F:\softwares\yarn\bin\yarn.CMD
npm: 6.12.1 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: 44.18362.449.0
npmPackages:
apollo-link-context: ^1.0.20 => 1.0.20
@apollo/client: "^3.0.0-beta.43",
The text was updated successfully, but these errors were encountered: