Description
Issue Description
Reopening this old issue: #5438
We've had a few incidents in production triggered by trying to add properties to frozen Apollo cache objects. These operations fail at runtime, but are allowed by typescript since the cache results aren't typed with readonly
.
While ideally we never should modify the cache results, sometimes we change a query and want to write an adapter so we don't have to update all downstream components, so this is very easy to accidentally do if you shallow copy an object and try to push an element to a subfield.
I linked a codesandbox reproduction. FYI the template doesn't include Typescript out of the box, so had to add the typechecker plugin manually, but this shows that typescript won't catch the error.
Link to Reproduction
https://codesandbox.io/p/devbox/reverent-pond-8wgnss?workspaceId=ws_T8pRa7Jre9csCVyagESXB
Reproduction Steps
- Make an apollo query and return data
- Attempt to set a property on the data
- Apollo will throw an error at runtime, but provide no typesafety.
@apollo/client
version
3.11.4