-
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
Fetch policy no-cache returns null data #3030
Comments
Thanks for detailed report @razor-x. I have the same issue :) |
@rschef I need this to work in a system which doesn't know about react and uses this client directly, so unfortunately that workaround won't be an option for me. I poked around a little in QueryManager.ts but I couldn't find an obvious reason for this bug. I'm hoping someone more familiar with the code will be able to prioritize and find this quickly. I would consider this a serious bug as I could rephrase the issue as apollo-client does not support the most basic GraphQL operation: running a query and returning the correct result (without the added complexity of caching). |
It's this code: apollo-client/packages/apollo-client/src/core/QueryManager.ts Lines 1059 to 1112 in 6eec674
It was introduced in #2934 Basically, if The branch needs to be updated to use
Not sure what implications that has. I'm running into this right now because the cache actually seems to be causing performance issues in our use case and I wanted to try bypassing it; but I can't due to this bug :( If I can figure out how to develop this locally, I could try updating it. @jbaxleyiii Should I try to update the branch as I mentioned to fix this issue? Do you see any issues with that approach? |
Alright, I am debugging this issue actively. I think my "fix" will work, however there's another problem. In QueryManager, the
If I'm a little disappointed, because a simple test showcases this bug.
Now I'm trying to figure out the best way to essentially get the data in a place |
I have the tests passing, I just have it use |
* Set query newData if using no-cache fetch policy and set resultFromStore * Add tests for no-cache fetch policy * Get VSCode to run jest for apollo-client for debugging * Update authors/changelog * Move tests to appropriate location * Pass through no-cache fetch policy
I'm getting an eerily similar issue (same data shape, despite getting a valid gql response, default fetch policy), but only when building minified production assets for the apollo-client. That leads me to believe it's something in our code, but I'm not sure if any apollo libs look for |
Any updates on this? |
This makes things pretty much unusable for me in some cases. I tried no-cache to actually get a proper loading indicator, as with the default fetch policy loading sometimes returns false even tho data is being loaded from remote. Now I get a proper loading indicator, but data is undefined (not null as others report) when loading finished. Changing things back to the default fetch-policy gives me the data, but again a misleading (false) loading state. 🥜 |
This was fixed in release 2.3.8 by hwillson |
I'm still having this issue (data is {}) on 2.4.2 |
Is there a reason why returnPartialData is true? This was hiding an error and returning { data: undefined, networkState: 7, stale: true } for me. I had forgotten to query for the id of an object and watchQuery could not find it in store. With returnPartialData false i was able to get an error about missing property and finally find the problem. With this true all i was getting from watchQuery was { data: undefined, networkState: 7, stale: true }. Maybe related issues: apollographql#3030 , apollographql#2914
I'm still having this issue with the latest version 2.4.5
output is:
but I could see the results in the network section in my browser and I could get non null data only If I add this to my apollo client:
|
@kamranayub this issue still persists randomly. From what we could gather, for no apparent reason, once every few times (less than 10 in our case) the Query component will trigger twice when We have replaced all our "no-cache" policies with "network-only" and will continue monitoring. Please re-open this issue or let me know if I need to open a new one. |
I have the same issue as @thanpolas, also happening erratically. Running version
instead of the expected:
|
Confirming that this is still an issue. We're encountering this when mocking network requests during E2E tests with Cypress. |
After several trails I figured
I've also noticed we'll get a In my particular case, my backend never serializes Does anyone have an idea why those missing fields break the result causing this issue? |
Seeing something that could be related to this but do not have the ability to reproduce ATM. We have a query that is inside of a component that is not being re-rendered (checked with consoles on render()) but the context provider for the query returns null for data. Using |
We encountered this issue and resolved via insight from @jdorleans's comment. When the response does not include a field you're expecting the entire |
I forgot to mentioned I created a new issue (#4267) to keep track of the problem I'm facing since it might differ from this one here. |
Have same issue on apollo-client@2.4.12, why this is closed? |
The same problem with the Query component. It returns normal data once, then data = {} with the same query (nothing is changed just component is rerendered) when fetchPolicy is 'no-cache' |
Ironically, this happens for me when my policy is "network-only". Switching to "no-cache" (what's the difference, by the way? both are making the network request anyways) fixes it. |
@rivertam are you using the client and setting "network-only" or the Query component? |
@audiolion Client in this case |
@rivertam use Query if you can, its a bug in apollo client, see |
@rivertam Same here. Using Apollo Client, switch to "no-cache" solve the problem |
I'm actually experiencing this issue from multiple sides. Why is this closed again? There's not even a workaround, save an actual fix for this. |
I'm with the same problem that @jdorleans. |
Still having the same issues as @bozskejkaja |
I still having the same issues with |
|
Same issue. |
All my problems were solved with errorPolicy: "all"
|
This insight from @jdorleans resolved the issue for me. |
@jdorleans You have no idea how many hours you saved me. I was going in a rabbit hole trying to find the answer. Thank you |
Intended outcome:
Run a query and receive non-null data when using
fetchPolicy: 'no-cache'
. Tested on Node and in Browser.Actual outcome:
The
data
property isnull
:How to reproduce the issue:
Node.js
data: {...}
). (expected)no-cache
fetch policy: the Promise will eventually resolve with no data (data: null
). (unexpected)network-only
fetch policy: the Promise will eventually resolve with good data. (expected)Browser
clientA
works with default fetch policy: returns non-null data. (expected)clientB
does not work withno-cache
fetch policy: returnsnull
data. (unexpected)clientC
works with default fetch policy (returns non-null data), then the query is repeated again withclientC
, this time withno-cache
fetch policy, and the data returns non-null! (what?)Version
Contents of the runkit for reference
Contents of the browser example for reference
The text was updated successfully, but these errors were encountered: