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

Clear current ApolloStore related interceptors when calling .store() on builder #5857

Merged

Conversation

rohandhruva
Copy link
Contributor

@rohandhruva rohandhruva commented Apr 28, 2024

I noticed a bug when using .newBuilder().store() on an existing ApolloClient. The intention was to set a different ApolloStore() using builder.store(...) on this client. But after .build() on this new client, I noticed that .watch() was not working when I wrote some data to the new store.

Turns out that we were ending up with 3 duplicated watchers, the ones that are added by .store() function.

image

This PR fixes that problem by clearing the 3 store related watchers when using .store() on a builder.

  • Introduced a new internal interface ApolloStoreInterceptor to indicate these interceptors
  • In ClientCacheExtensions, clear them in ApolloClient.Builder.store() function
  • This required introducing a new removeInterceptor() API

I am not sure if making removeInterceptor() a part of the builder API is desirable, but I couldn't think of a way to make this work without introducing such an API. Let me know if you have other approaches I can try for this.

Copy link

netlify bot commented Apr 28, 2024

👷 Deploy request for apollo-android-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 496c094

Copy link
Contributor

@BoD BoD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! 🙏 We have other similar cases in the codebase, I'll follow-up with another PR to fix them.

@BoD
Copy link
Contributor

BoD commented Apr 29, 2024

(I just added a commit to also do the same in the incubating version)

@BoD BoD merged commit a8737d1 into apollographql:main Apr 29, 2024
5 checks passed
@rohandhruva rohandhruva deleted the rdhruva/store_clear_current_interceptors branch April 29, 2024 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants