Initializing the Normalized Cache with `CacheKeyResolver` & Relay Style Pagination Constructs.
Question
Hi Team, 👋
In continuation to the issue#5666, I noticed that in the latest v4.0.0 Snapshot the normalized cache cannot be initialized using CacheKeyResolvers along with the MetadataGenerator, RecordMerger, FieldNameGeneratorand EmbeddedFieldsProvider.
Are there any plans to introduce an API which can initialize the Normalized Cache using the CacheKeyResolvers and the Relay Style Pagination constructs?
Thanks
Hi!
In the incubating version we've started transitioning to ApolloResolver to replace CacheResolver. It is the same thing but with a slightly different API that will help with evolving the library in a non-breaking way. The version of ApolloStore() that accepts the FieldNameGenerator etc. is expecting an ApolloResolver.
However there is no ApolloResolver version of CacheKeyResolver - we should definitely add it. In the meantime you can transform your existing resolver into an ApolloResolver with something like:
class ApolloCacheKeyAdapter(private val cacheKeyResolver: CacheKeyResolver) : ApolloResolver {
override fun resolveField(context: ResolverContext): Any? {
return cacheKeyResolver.resolveField(variables = context.variables, parent = context.parent, parentId = context.parentKey, field = context.field)
}
}
and pass ApolloCacheKeyAdapter(yourExistingCacheKeyResolver) to ApolloStore().
Done in https://github.com/apollographql/apollo-kotlin/pull/5970. Additional work on the incubating cache now happens in https://github.com/apollographql/apollo-kotlin-normalized-cache-incubating.
Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Kotlin usage and allow us to serve you better.