From 96178f3dd72199cbf629ebdaef6bcec933952876 Mon Sep 17 00:00:00 2001 From: Martin Bonnin Date: Wed, 13 Dec 2023 10:34:44 +0100 Subject: [PATCH] Documentation updates. (#5469) (#5473) Co-authored-by: Arjan Mundy <97124666+ArjanSM@users.noreply.github.com> --- docs/source/caching/programmatic-ids.mdx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/source/caching/programmatic-ids.mdx b/docs/source/caching/programmatic-ids.mdx index 34bbdd4f8f3..530e64e782d 100644 --- a/docs/source/caching/programmatic-ids.mdx +++ b/docs/source/caching/programmatic-ids.mdx @@ -54,6 +54,14 @@ val cacheKeyGenerator = object : CacheKeyGenerator { You can also use the current object's typename to use _different_ cache ID generation logic for different object types. Note that for cache ID generation to work, your GraphQL operations must return whatever fields your custom code relies on (such as `id` above). If a query does not return a required field, the cache ID will be inconsistent, resulting in data duplication. +Also, using `context.field.type.leafType().name` yields the typename of the Union as opposed to the expected runtime value of Union received in the response. Instead querying for the `__typename` is safer. +To make sure `__typename` is included in all operations set the `adTypename` gradle config: +``` +apollo { + addTypename.set("always") + // +} +``` ## `CacheKeyResolver`