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.

InMemoryCache storing values as `null`.

See original GitHub issue

My GraphQL API doesn’t use id, it uses uuid on many fields. This silently causes a InMemoryCache to store the object under the key {TYPE}:null, which causes an overwrite when multiple objects are resolved.

Intended outcome: Not entirely sure, I feel like the InMemoryCache should throw an error.

Actual outcome: Instead InMemoryCache caches the object under {TYPE}:null.

How to reproduce the issue: Using a graphQL API that returns anything other than id, have a Node that doesn’t have an id field, or a query that doesn’t include the id. Apollo-client’s InMemoryCache will store the node under the key {TYPE}:null. Subsequent queries, or queries that return multiple nodes all overwrite the same cache, which means all the Nodes have the same data.

Versions System: OS: macOS Mojave 10.14.6 Binaries: Node: 10.16.3 - ~/.nvm/versions/node/v10.16.3/bin/node Yarn: 1.22.4 - /usr/local/bin/yarn npm: 3.9.5 - ~/projects/website/node_modules/.bin/npm Browsers: Chrome: 81.0.4044.129 Firefox: 75.0 Safari: 13.1 npmPackages: @apollo/client: 3.0.0-beta.41 => 3.0.0-beta.41

Thanks, I tried finding this in existing issues to no avail, I apologize if this is a duplicate / known issue.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

2reactions
jguffeycommented, May 1, 2020

Yeah this was the solution for me.

I opened a ticket because I thought that some sort of warning (when there’s no ID for caching), might be useful for other developers. It took me awhile to debug that it was a cache failure, because apollo-cache just kept returning the same record, I spent a lot of time thinking the problem was with my GraphQL API.

1reaction
mgasnercommented, Jul 22, 2022

this is very confusing when you hit it and you can still hit it if your query doesn’t return the appropriate keyFields

Read more comments on GitHub >

github_iconTop Results From Across the Web

class InMemoryCache - Apollo GraphQL Docs
Returns the requested data or null if data is not available in the cache. For usage instructions, see Interacting with cached data: readFragment...
Read more >
ASP.NET can't cache null value - Stack Overflow
Getting the value for a key that doesn't exist throws a KeyNotFoundException, and storing a null value is valid.
Read more >
Cache in-memory in ASP.NET Core - Microsoft Learn
Learn how to cache data in memory in ASP.NET Core. ... IMemoryCache represents a cache stored in the memory of the web server....
Read more >
Guava Cache - Baeldung
First, we'll create the CacheLoader, which is used to compute the value stored in the cache. From this, we'll use the handy CacheBuilder...
Read more >
Customizing the behavior of cached fields - Client (React)
An array of key arguments that help the cache avoid storing unnecessary duplicate data. You provide field policies to the constructor of InMemoryCache...
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