InMemoryCache storing values as `null`.
See original GitHub issueMy 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:
- Created 3 years ago
- Reactions:1
- Comments:5
Top GitHub Comments
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.
this is very confusing when you hit it and you can still hit it if your query doesn’t return the appropriate
keyFields