question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Referential identity of arrays lost when setting the cache in client resolvers

See original GitHub issue

Intended 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:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
NickClarkcommented, Apr 9, 2019

Seems to be working well. Thanks!

1reaction
NickClarkcommented, Apr 5, 2019

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”).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring the Apollo Client cache - Apollo GraphQL Docs
This article describes cache setup and configuration. ... import { InMemoryCache, ApolloClient } from '@apollo/client'; ... array for their keyFields.
Read more >
Customizing the behavior of cached fields - Client (React)
When the write occurs, the field's new value is set to the merge function's return value, instead of the original incoming value. Merging...
Read more >
Cache data may be lost when replacing the my field of a ...
I read the documentation and realized that the problem is in the apollo client cache (typePolicies).
Read more >
Fine Tuning Apollo Client Caching for Your Data Graph (Ben ...
Learn how to customize the Apollo Client cache to suit your weirdest data modeling and reactivity needs, using the all-new cache API in ......
Read more >
Extensions - AWS AppSync
$extensions contains a set of methods to make additional actions within your resolvers. $extensions.evictFromApiCache(String, String, Object) : Object.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found