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
TypeError: Cannot assign to read only property #5903
Comments
This is intentional. Directly mutating the cache would often result in buggy behavior, so in v3 the cache is now readonly. If you need to change the data in the cache you will now need to make copies of your data before mutating. |
this should work: const { data, client } = useQuery(GET_GROUPS);
const onSkillSelect = id => {
setSkill({ variables: { id, skills: props.skills } });
};
const toggleSwitch = () => {
const newDataGroups = [...data.dataGroups];
newDataGroups[props.id] = { ...newDataGroups[props.id], isSkillsDisabled: false };
const newData = { ...data, dataGroups: newDataGroups };
client.writeData({ data: newData });
} |
The Apollo Client 2.6 blog post explains the benefits of immutability, and why it's becoming mandatory in Apollo Client 3.0: https://blog.apollographql.com/whats-new-in-apollo-client-2-6-b3acf28ecad1
If your first instinct in response to an error like this is to "override" the library that's giving you the error, you're starting off on the wrong foot. Please try to understand what's going on first, or at least realize that the errors may be for your own good, before you jump to conclusions about possible workarounds. This issue tracker is for tracking bugs and features in the Apollo Client library, not a help desk for quick solutions to common problems that could be solved by reading the documentation on your own time. |
it only happens in local develpment but not in prod. Is that intended as well? |
You can use cloneDeep of loash to copy the result. |
Yeah, its only appear on local development. When I deploy the project the errors not showing up. |
I'm keep getting this error
when i'm trying to mutate something from the cache.
I'm using 3.0 beta client react
any idea how to override the cache?
The text was updated successfully, but these errors were encountered: