-
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
watchQuery over-fetching #7114
Comments
I believe I am encountering the same issue in our Apollo Client 3.2.2 project. In our case, we have 2 sibling components, each initiating a |
Pretty sure I'm having the same issue as well. We use In dev, our webapp still function properly, however, after In production, both the correct and unnecessary query are still being fired off, however, the paginated results only appear on the screen for a split second and then vanish making apollo client unusable for further production deployment until either a workaround is found or a fix is pushed. The differences between dev and prod may be explained due to significantly increased latency in dev (issues in production may be the result of a race condition) although I haven't had the time to drill down to see why results show as expected in dev and disappear in production. I spent some time in the chrome debugger and found the extra unnecessary query is coming from https://github.com/apollographql/apollo-client/blob/main/src/core/Reobserver.ts#L52 . I've also found that One workaround I've thought of is setting the initial fetch to return 0 results, set the Query component's fetch policy to |
In case anyone else is trying to figure out how to get around this problem, I can confirm that the workaround I mentioned above works. We've had so many issues with apollo's cache and endless scroll that we've completely circumvented apollo's cache on any page that uses pagination/endless scroll and are instead using component state in our endless scroll component. |
@CaptainHansen I would love your critical feedback on this documentation-in-progress about AC3 pagination: #7175 (preview). You might also try using |
@klemenoslaj In your reproduction, because you're sending your You can fix this by giving your this.apollo.watchQuery<Query>({
fetchPolicy: 'cache-only',
query: gql`
query justIds {
posts @client {
id
}
}
`,
}) |
@benjamn thanks for the reply. My point is, what if I genuinely want to go trough the network for both requests? I hope the reproduced behavior is not as expected. |
@klemenoslaj This behavior hinges on your answer to a question that the cache cannot answer for you: is there just one list of In the first case, since one query requests fewer fields for each post than the other query, the other query will find the post objects from the
In the second case, you now have two independent copies of what is arguably the same data, so you have to worry a bit more about consistency between those two related-but-separate lists of data. If you're interested in this approach, configuring a custom |
Shouldn't it be the other way around?
I would expect this to be the end. However for some reason the 3rd request is made with the What you're saying is this (if I got it right, otherwise sorry 😇 ):
What I am saying is this:
What I don't understand is why the |
same issue here with fetchMore. |
Also experiencing this issue with apollo 3.0.0 In our case we have 2 sibling components calling Every time one sibling component subscribes to a |
Intended outcome:
When having active watchQuery in one component and triggering another watchQuery deeper in the component tree only the one deeper in the tree should create a new network request.
The 1st query should not be triggered together with the 2nd query. If any field shared between the two queries changes with the response of 2nd query, the 1st watchQuery should update due to cache changes anyway.
Example
1st query
2nd query
Actual outcome:
When the 2nd query is executed, the 1st query is sending a new network request again effectively over-fetching.
How to reproduce the issue:
Reproduction: https://stackblitz.com/edit/simple-apollo-angular-example-maz5cx
Keep refreshing with the stackblitz refresh button and more often than not (gif below).
Versions
The text was updated successfully, but these errors were encountered: