cacheExchange doesn't work properly #1248
-
I created a code and is working perfect with base urql. But when installed cacheExchange it's stopped to work properly. I followed the instructions in the documentation but in any case it doesn't work. I created a demo live from the a branch. This is file with the cacheExchange configuration. I have two problems: I've been reading the documentation and try to fix it, but unfortunately I've been no able to make it's work. Please help me with that, I really want to understand this library! import { cacheExchange as cacheExchangeURQL } from '@urql/exchange-graphcache';
import { TranslationsDocument } from 'graphql/generated';
const cacheExchange = cacheExchangeURQL({
keys: {
Pagination: () => 'Pagination',
TranslationPaginationResponse: () => 'TranslationPaginationResponse',
UserPaginationResponse: () => 'UserPaginationResponse',
},
updates: {
Mutation: {
translationDelete: (_result, { id }, cache) => {
console.log(cache.readQuery({ query: TranslationsDocument }));
cache.updateQuery({ query: TranslationsDocument }, (data) => {
// 'data' always is null :(
console.log(data, id);
return data;
});
},
},
},
});
export default cacheExchange; |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hiya 👋 sorry, I currently don't quite have the time to go into a full detailed investigation and explanation, so let's start slow. The first thing that stands out to me with the configuration you've posted is that the Specifically, there are unkeyable entities (ones that don't have any Generally as for the update, I don't have time unfortunately to look through all your code 😅 it'd take some substantial time to look at all of it; however, if you're struggling with thinking about what a normalised cache does, how it resolves your query, and which parts of the configuration matter this may help: https://kitten.sh/graphql-normalized-caching It's also worth mentioning that your updates that you pass to |
Beta Was this translation helpful? Give feedback.
Hiya 👋 sorry, I currently don't quite have the time to go into a full detailed investigation and explanation, so let's start slow.
The first thing that stands out to me with the configuration you've posted is that the
keys
configuration you've created returns static strings. This will start sharing entities, hence potentially overwriting results from two separate entities. Now, this can be valid in some cases but those should be rare.Specifically, there are unkeyable entities (ones that don't have any
id
or ID-like fields) and ones that do have a key. Either of these are unique by a key. Unkeyable entities will however be unique to their location on the parent entity. Shared entities wit…