Skip to content
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

Changing local state reactive variable refetches the query via remote network request #7612

Closed
JayBee007 opened this issue Jan 25, 2021 · 1 comment
Assignees

Comments

@JayBee007
Copy link

Intended outcome:
Adding currently selected ids of a todo to a local state reactive variable (an array of ids) should update the local fields only.
For example: isSelected for every todo is calculated by checking todo.id in the local state reactive variable.

Actual outcome:
When adding the todo.id to the local state reactive variable, the remote query, which uses the @client directive for getting isSelected field of the todo, re-fetches the data via network request

How to reproduce the issue:
https://codesandbox.io/s/apollo-client-3-starter-forked-7i8wy

Versions

@apollo/client - 3.3.7
graphql - 14.7.0
react - 16.12.0
react-dom - 16.12.0
react-scripts - 3.0.1
@benjamn benjamn self-assigned this Feb 4, 2021
@benjamn
Copy link
Member

benjamn commented Feb 5, 2021

@JayBee007 The reason for the network request is that you're passing fetchPolicy: "network-only" to useQuery in src/hooks/useTodos.js. If you switch that option back to cache-first (the default), your cache updates will update the UI without making a network request (because reading from the cache succeeds).

You should also update to @apollo/client@3.3.8 (just published), which includes #7657, which fixes a bug in broadcasting reactive variable changes that was preventing cache-first from working correctly, in your reproduction.

Thanks to your reproduction, I'm confident this is fixed in v3.3.8, so I'll go ahead and close this issue, but please feel free to comment here if you're still having problems.

@benjamn benjamn closed this as completed Feb 5, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
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