fred
08/07/2025, 9:51 AMCreateSomethingMutation and a SomethingQuery (code in the thread) — they both return the same thing (semantically), but they're both different from each other in structure/arguments, which means this happens:
• CreateSomethingMutation is called and we cache its result
• SomethingQuery is then observed (cache only) but we then get a cache miss
our current workaround is to manually get the result from the mutation and add it to the cache as if it was the result of the query, and then everything works fine, but this seems like a common scenario so I thought I'd check if there's any better way to handle this (e.g. tweaking somehow the graphql structure?)fred
08/07/2025, 9:51 AMmutation CreateSomethingMutation(
$somethingInput: SomethingInput!
) {
createSomething(somethingInput: $somethingInput) {
something {
...SomethingFragment
}
}
}
query SomethingQuery($somethingId: String!) {
something(somethingId: $somethingId) {
...SomethingFragment
}
}bod
08/07/2025, 9:53 AMsomething have an id?fred
08/07/2025, 9:53 AMfragment SomethingFragment on Something {
id
# other properties
}bod
08/07/2025, 9:54 AM@typePolicy ?Eduard Boloș
08/07/2025, 9:57 AM@typePolicy, we have a CacheKeyGenerator that just returns the id of the object 🫣bod
08/07/2025, 10:01 AM@fieldPolicy so the cache knows where to look for something(somethingId: $somethingId)?Eduard Boloș
08/07/2025, 10:02 AMbod
08/07/2025, 10:03 AMEduard Boloș
08/07/2025, 2:07 PMFieldPolicyCacheResolver was prepending the typename to the cache key. But like I was saying above, we have a CacheKeyGenerator that just returns the ID, without the typename prefixed (which I think it's unfortunate in retrospect, due to possible collisions), so we were getting exceptions like com.apollographql.apollo.exception.CacheMissException: Object 'Something:SomethingId123' not found. We just reimplemented our own CacheResolver that just joins the key args, skipping the typename prefix, and it all worked like a charm ✨
Thanks for your prompt guidance as always! 🙂bod
08/07/2025, 2:14 PMEduard Boloș
08/07/2025, 2:16 PM