-
Notifications
You must be signed in to change notification settings - Fork 734
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
Parity with Apollo Kotlin: Ability to Observe ApolloStore Changes? #3350
Comments
Thanks for the request and all the details. It really helped me to have the references to the past discussions! I'm very open to doing this at this time. The discussion about subscribers being strongly retained in #2300 just means that we need some documentation around this that indicates that a subscriber needs to be unsubscribed from the store before you let it go out of scope or it will be retained. There are plenty of easy ways to ensure that you're doing that, and this is more of an advanced API, so I'm okay with just requiring users to be responsible for that. In the future, I'd love to improve on this API and make it harder to create retain cycles there, but for now, I think it's fine to just document it. I'd be happy to get this out for our next release. But if you'd like to make the contribution, feel free to open up a PR and make this API public! |
Thanks so much for the fast response, @AnthonyMDev - and glad to hear y'all are open to opening up this functionality! I agree some strong docs can help avoid foot-guns re: retain cycles, here. I'll aim to get a PR up later today; may need your help to iterate on the best copy for that comment, once the PR is up. |
Apollo Kotlin currently provides a public API to get notified when objects in the ApolloStore are updated. iOS has a similar facility as well, but it has not been a public API. This change exposes the ApolloStoreSubscriber for public use. Refer: apollographql/apollo-ios#3350
Apollo Kotlin currently provides a public API to get notified when objects in the ApolloStore are updated. iOS has a similar facility as well, but it has not been a public API. This change exposes the ApolloStoreSubscriber for public use. Refer: apollographql/apollo-ios#3350
(Full context in apollographql/apollo-ios#3350.) Apollo Kotlin currently provides a public [`changedKeys`](https://github.com/apollographql/apollo-kotlin/blob/v4.0.0-beta.5/libraries/apollo-normalized-cache/src/commonMain/kotlin/com/apollographql/apollo3/cache/normalized/ApolloStore.kt#L27-L30) property to get notified when objects in the ApolloStore change. Internally, iOS has had a similar facility, too -- but it hasn't been `public` until now.
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
Hey, Apollo team!
I recently joined a startup that has built some custom SwiftUI tooling on top of Apollo iOS. Specifically, we've built a
@Sync
property wrapper that (under the hood) watches the Apollo Store for cache changes, and then updates the view via binding. To support this, the team forked Apollo so they could observe changes in theApolloStore
via anApolloStoreSubscriber
instance in our app. I'm looking at options that will get us back onto Apollo's mainline. 😃There have been similar discussions around making
ApolloStoreSubscriber
a public API in 2019 (ref: #630) and 2022 (ref: #2300). Importantly, some of the risks brought up in 2019 have been assuaged by general refactoring on the ApolloStore APIs (no longer are thereUnsafeMutableRawPointer
).As a reference, Apollo Kotlin does currently expose this functionality via a public property,
changedKeys
.Aside from observing the store directly, we've also considered using ApolloClient.watch(query:). But, it wouldn't allow us to update the UI when individual fragments change.
Anyway, appreciate any feedback/thoughts you have! Thank you - Jameson
Describe the solution you'd like
As an uber-collapsed TL;DR, I'm essentially inquiring about adding
public
to these four lines: 1, 2, 3, 4.The text was updated successfully, but these errors were encountered: