Allow passing a function to keys
in Graphcache config
#1271
Replies: 2 comments 4 replies
-
We chose the less intrusive option here as we don't want every code path in every application to be disturbed by this, basically 😅 We could add a global modifier but seeing as this is related to pagination, we do have exceptions for these warnings in place for type names that comply with the Relay pagination spec https://github.com/FormidableLabs/urql/blob/8224ed0c5dbc31d62102254d50d9c1584c84c601/exchanges/graphcache/src/operations/write.ts#L308 I guess I can look into this though, but we consider these changes carefully as most of the time we don't decide on features by edge cases per user, sorry 😅✌️ |
Beta Was this translation helpful? Give feedback.
-
Sorry to necro this discussion, but I stumbled upon it via google. Here's an interim hack that seems to work for this case without any change to urql itself: cacheExchange({
keys: new Proxy(
{},
{
get(_target, prop) {
switch (prop) {
case 'Todo': return data => data.name;
case 'Product': return data => data.productId;
default: return () => null;
}
},
}
),
}), |
Beta Was this translation helpful? Give feedback.
-
I'm currently experimenting with Graphcache in an existing application. I find it really cool but there is something which bugs me a lot :) I see tons of warnings like this one:
This suggests to add
PaginatedPosts: () => null
to thekeys
config if I'm okay with embedding the entity to the parent entity, which is exactly what I want in most of the cases.My problem is that the GraphQL API I'm using have hundreds of types and I would like to avoid adding all of them one-by-one to the
keys
config if that's possible. I know this is just a warning in dev mode only, but it causes lot of noise.What do you think about adding support for passing a function to
keys
which would receive thetypeName
as param so we could programmatically generate the keys config? Like this:Config with object (existing solution):
Config with function (proposal v1):
Config with function (proposal v2):
Apollo has (had?) a similar solution as well, I think that's quite useful for devs.
Beta Was this translation helpful? Give feedback.
All reactions