-
Notifications
You must be signed in to change notification settings - Fork 730
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
Build a better way for users to derive a cache key in a type safe way #3478
Comments
Thanks for creating the issue @PSinha1202.
I don't think we'd allow full customization of the cache key but being able to derive the same cache key for manual read/write transactions as is used for response-based cache persistence is likely where we'll end up. |
I do agree that right now this isn't great. The user needs to input a stringly-typed value that is derived from implicit knowledge the developer needs to have about the way we construct cache keys. This is very far from ideal. I'm not sure what the solution looks like though. At the time of calling |
Thanks for the information and please correct me if i am wrong. We have this func
which defines the CacheKeyInfo and is being sent to transaction metadata. But it keep the format always as
Will it solve the entire problem? Possibly No. But since |
Ah, I see. It sounds like you are asking for a way to bypass the prepending of the I think a better addition would be to add a new method: Would that resolve this for you? |
ohh yeah, i din't thought about it. yes adding a new method to send |
Okay great! I'll create a new issue to track that and close this one out. Not sure exactly when we'll get to this work, but if you'd like to take a crack at writing a PR for it yourself, we're always happy to have contributions! |
Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo iOS usage and allow us to serve you better. |
Use case
More details here:
https://community.apollographql.com/t/how-can-we-avoid-sending-hardcoded-format-while-reading-fragment/7951/3
Can we have a better way to send the non-hardcode key as defined below
ref: Direct cache access - Apollo GraphQL Docs - Apollo Doc
let data = try transaction.readObject(
ofType: HeroDetails.self,
withKey: "Hero:123"
)
The reason is when we updated the SDK, we missed changing the cacheKey format, and we hit an issue since theing that key format. Trying to avoid such things in the cacheKey format had changed and we missed updat future.
We set the format of cacheKeyInfo as below, as defined in doc.
cacheKeyInfo(for type: ApolloAPI.Object, object: ApolloAPI.ObjectData) -> CacheKeyInfo? {
guard let id = object["id"] as? String else {
return nil
}
return CacheKeyInfo(id: id)
}
Describe the solution you'd like
Build a better way for users to derive a cache key in a type-safe way. Giving caller more custom formatting of CacheKey, so we can avoid the above issues in future.
The text was updated successfully, but these errors were encountered: