-
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
Misleading documentation with regards to query
's fetchPolicy
allowed policies
#3130
Comments
Yes, its not clear at all why u cant use cache-and-network with query.... |
I too have this problem.
|
I have this issue too. Is there any explanation for the restriction on using |
Any update for this issue? |
wondering about this as well, or how to use watchQuery in tandem with query to manually fire a cache-and-network query. |
Is there a workaround for this? |
Any update on this ? This is very strange! I expected the query to return initially from cache and make the request in the meantime then the component will get updated with fresh data! |
It appears "cache-and-network" policy does work with the new Query component, but not with client.query as everyone has found. I am not sure if this was the intended behavior or not but it is extremely frustrating given the incorrect documentation and no real example using watchQuery. |
@mikebm I was curious about this as well since cache-and-network was working fine with the Query component, but looking under the covers a bit it seems like the Query component actually does use watchQuery: https://github.com/apollographql/react-apollo/blob/1c666276b2206ae882fed3cc0bf6de38ab5432d8/src/Query.tsx#L277 I only looked briefly so I could be wrong, but maybe the Query component implementation could at least serve as an example of how to use the client "properly". edit: linked to wrong line at first |
Is this still a thing? |
Yes. See the following code: |
Hi, Hey @hwillson or @peggyrayzis can we get some movement on this issue please? This is impacting a large number of people and we really need a bug fix. :-) Thanks! |
@cyberdude this issue is specific to |
Ahh right, sorry, I was confusing this with another one about missing documentation. Deleting original useless comment I made. Thanks. |
Oh man still not resolved 😭I've had soooo much problem with Apollo docs today regarding local state and thought I was finally on a roll until I tried to implement something that seemed like core functionality only to find it doesn't work :( Is there a work around for this or do we just need to use |
Duplicated.... #3880 Scott |
The current method signature is: apollo-client/packages/apollo-client/src/ApolloClient.ts Lines 331 to 333 in 166f28f
So because That means However we can reduce friction for new users by enforcing this constraint by splitting up export type FetchPolicy =
| 'cache-first'
| 'network-only'
| 'cache-only'
| 'no-cache'
| 'standby';
export type WatchFetchPolicy =
| FetchPolicy
| 'cache-and-network'; @hwillson would you accept a PR for this kind of fix ? or would there be a more appropriate approach ? |
@PowerKiKi Yes, we'd definitely accept a PR for this - thanks! |
Any workaround/fix for this yet? |
While the error message could be improved, there is no logical bug to fix here. As @PowerKiKi explained above, the In other words, while this error doesn't do a great job of explaining itself (beyond the simple fact that It's also worth noting that React Apollo uses Given the misconceptions that have proliferated in this issue, it's very tempting to "solve" this issue by silently replacing |
I strongly disagree with that. It will only bring even more confusion to users as they specifically asked for a behavior that can never be valid, but the patch will unexpectedly change the behavior. This patch make Apollo less predictable and more obscure. The fetch policy is already hard enough to grasp not to introduce a Also it is very debatable what users actually want to do. In our case we replace Instead I believe we should teach users what is possible or not, and not allow them to have expectations that can never be full-filled. @hwillson already agreed on that alternative. Was it debated with him before implementing 70fdf25 ? Is there a chance to be reverted ? |
@benjamn it makes sense that given I will put my use-case here, maybe it will help clarify what I am trying to achieve. Apologies if it is the wrong place. I need to fetch from cache, then fetch from network if possible (what Thanks. |
@DavidStummer if you want |
@PowerKiKi thanks for the clarification. I think I got confused and now realise that |
I think throwing an error which states something like 'It makes no sense to use cache-and-network with ApolloClient#query, as this function returns promise' would educate new users quickly and avoid this confusion. |
…query. #3130 (comment) @PowerKiKi How does this look to you?
…query. #3130 (comment) @PowerKiKi How does this look to you?
@benjamn your last commit is exactly what I had in mind. This way TypeScript users are prevented to shoot themselves in the foot, thanks to the strong typing. And JS vanilla users would still get an error on runtime to inform very explicitly that they are doing something wrong. Thank you for taking the time to implement it. |
Hi @benjamn @PowerKiKi I'm a bit confused about this change. Now, Do edit: never mind! I see it's already fixed here. Thanks for the hard work and excited to be able to use the latest release! 🙂 (Is it worth noting that this change is breaking insofar as types are concerned?) |
@timhwang21 It might be a breaking change if you consider only the type system, but I think it better reflects what would actually happen if you tried to pass Longer term, I think the |
Just to make sure my own code isn't broken, this is disregarding types right? Just want to make sure |
Hi @benjamn - thanks for your hard work on Apollo. I've had several use cases where the declarative nature of I disagree because caching and coding style (declarative vs imperative) are orthogonal to each other and should remain so. For example:
These two points have nothing to do with each other and should not be connected. One is about coding style, the other is about data staleness. They are not and should not be related. I really feel uncomfortable that in order to use I really appreciate you all open-sourcing Apollo and I don't mean to sound like a whiner. I appreciate all your hard work. But I just don't understand why you can't add Or is the intention that we should use |
@timhwang21
@joelgetaction That's what
This is exactly the intention, and I don't think renaming the For anyone who didn't already know that |
This would be a great improvement, albeit breaking a ton of code of course. As newcomers it took us a long time to figure out that the existing Until that breaking change happen, it could be possible to emphasized in documentation that |
watchQuery unhadled promises cannot be caught. |
The reason why |
Intended outcome:
Set "cache-and-network" when querying directly from the ApolloClient.
Actual outcome:
Error message:
How to reproduce the issue:
Follow the documentation here and try to query via
client.query(...)
with fetch policy"cache-and-network"
.Version
The text was updated successfully, but these errors were encountered: