hey, using the new incubating caching artifacts. i...
# apollo-kotlin
a
hey, using the new incubating caching artifacts. i got the paginationArgs
fieldPolicy
and a
typePolicy
correct. one missing piece is that it seems to use the index from the response as my caching key.
somepage.somepageCardsConnection.cards.3
as an example. The
id
I wish to use will reside in a nested field.
Copy code
contentBlockInfo {
        id
    }
is my best bet to use programmatic caching ids?
assume API is not changing at the moment to properly support caching ids
Copy code
object MonolithCacheKeyGenerator : CacheKeyGenerator {

    override fun cacheKeyForObject(obj: Map<String, Any?>, context: CacheKeyGeneratorContext): CacheKey? {
        if (obj["__typename"] === "SomepageCard") {
            @Suppress("UNCHECKED_CAST")
            return ((obj["contentBlockInfo"] as Map<String, Any?>?)?.get("id") as? String)?.let { CacheKey(it) }
                ?: TypePolicyCacheKeyGenerator.cacheKeyForObject(
                    obj,
                    context
                )
        }
        return TypePolicyCacheKeyGenerator.cacheKeyForObject(obj, context)
    }
}
b
I think you should be able to use
@typePolicy(keyFields: "id")
on
SomepageCard
?
oh sorry, if it's nested, that won't work indeed
I think yes, the programmatic way then.
a
cool thanks! yeah that worked. thanks for the input!