Referential identity of arrays lost when setting the cache in client resolvers
See original GitHub issueIntended outcome:
When I change cache entries, using either read/writeQuery
or read/writeFragment
in a client resolver, it should only change the property intended, and leave the referential integrity of everything else in tact.
Actual outcome:
Currently, it causes all properties to lose referential integrity. The arrays are changed. Although it seems when loading data from normal server requests behaves properly
How to reproduce the issue:
Just a rough example I was playing with. I can try to continue cleaning it up if necessary.
Make sure and start the server first. Clicking the refetch
button will result in every other fetch having the nested here
property matching (correct and intended). Clicking the setActive
button will result in the here
prop never being referentially sound (broken, unintended)
Server: https://codesandbox.io/s/6z2310j19z Client: https://codesandbox.io/s/y0yyvp8pzj
EDIT: Ok… so I was able to simplify it. Originals left for reference if desired https://codesandbox.io/s/oqnk90k68q
Versions
System:
OS: macOS High Sierra 10.13.6
Binaries:
Node: 10.15.0
Yarn: 1.15.2
npm: 6.4.1
npmPackages:
apollo-angular: ^1.5.0 => 1.5.0
apollo-cache-inmemory: ~1.6.0-beta.1 => 1.6.0-beta.1
apollo-client: ^2.6.0-beta.1 => 2.6.0-beta.1
apollo-link: ^1.2.11 => 1.2.11
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
Seems to be working well. Thanks!
I haven’t taken a deep look into the issues you’ve described, Right now it’s just troublesome in the view to have to check every element of an array just to decipher if it has changed. The logic is beautifully simple when normal immutability rules are followed. But there may also be a deeper issue here as well. Since in my current project, simply checking the identity of the elements was not enough, since there was, more deeply nested, arrays in the state. Oddly enough, nothing seemed to have changed, but nothing nested in the array had maintained identity. I have been really enjoying/getting used to the idea of client state in Apollo, but little issues like these seem to crop up, making me wonder if not many people use Apollo for local state, yet. Anyways, I’ll help however I can. Right now this one issue is problematic and really inconsistent from how just the normal loading of new data from the network works (which “just works”).