Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

network-only returns a cached value for a different query #3684

Closed
Falieson opened this issue Nov 12, 2019 · 7 comments
Closed

network-only returns a cached value for a different query #3684

Falieson opened this issue Nov 12, 2019 · 7 comments

Comments

@Falieson
Copy link

Falieson commented Nov 12, 2019

With
"@apollo/react-hooks": "3.0.0",

I make a useQuery request in one component, and then another makes a useQuery request, whichever resolves last then becomes the value of the other component. They are different queries!

my client is configured for "network-only", adding "no-cache" option to useQuery fixed the issue.

Someone else posted the solution 8 days ago on this closed thread: #556

@dylanwulf
Copy link
Contributor

I think this is actually intentional behavior. Looking at the docs for network-only:

This fetch policy will never return you initial data from the cache. Instead it will always make a request using your network interface to the server. This fetch policy optimizes for data consistency with the server, but at the cost of an instant response to the user when one is available.

I think the keyword here is initial. It will not return initial data from the cache. But once the initial data has been returned, network-only queries are subscribed to the cache and receive updates from the cache.

@Falieson
Copy link
Author

The problem I am having is that the useQuery hook is returning the cache update of a different query.

@dylanwulf
Copy link
Contributor

I agree that that behavior is unexpected and (in most cases) unwanted. But I don't think it counts as a bug. Maybe you could file an issue over at https://github.com/apollographql/apollo-feature-requests/issues ?

@Falieson
Copy link
Author

So the intended usage of useQuery(query, options) is to return the last value returned by any currently running instance of the hook? They don't register a new cache-id per query?
Essentially, out-of-the-box you can't ever use more than 1 useQuery at a time per view?

@Falieson
Copy link
Author

Falieson commented Nov 12, 2019

I'm going to update the description here to say that this is an issue w/ 3.0.0 , I'm getting an issue now that makes me believe I may not have rebuilt my dev server w/ 3.1.3 like I thought.

@dylanwulf
Copy link
Contributor

You can definitely use more than 1 useQuery at a time. But if you use multiple useQuerys that fetch the same data at the same time, then they will update each other. That's how the cache works.

@Falieson
Copy link
Author

thanks dylan, that actually is very helpful in my understanding. I'm going to close this since its an old version, hopefully others will find this discussion helpful

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants