Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initializing the Normalized Cache with CacheKeyResolver & Relay Style Pagination Constructs. #5964

Open
ArjanSM opened this issue Jun 13, 2024 · 1 comment

Comments

@ArjanSM
Copy link
Contributor

ArjanSM commented Jun 13, 2024

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

@BoD
Copy link
Contributor

BoD commented Jun 13, 2024

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().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants