Skip to content

Add cacheInterceptor() and autoPersistedQueriesInterceptor() #6455

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

Merged
merged 6 commits into from
Apr 8, 2025

Conversation

martinbonnin
Copy link
Contributor

@martinbonnin martinbonnin requested a review from BoD as a code owner April 7, 2025 17:55
Comment on lines -126 to -131
// Removing existing interceptors added for configuring an [ApolloStore].
// If a builder is reused from an existing client using `newBuilder()` and we try to configure a new `store()` on it, we first need to
// remove the old interceptors.
val storeInterceptors = interceptors.filterIsInstance<ApolloStoreInterceptor>()
storeInterceptors.forEach {
removeInterceptor(it)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not an issue anymore!

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe the ApolloStoreInterceptor interface can also be deleted, then?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good call! → #6612

@svc-apollo-docs
Copy link
Collaborator

svc-apollo-docs commented Apr 7, 2025

✅ Docs preview has no changes

The preview was not built because there were no changes.

Build ID: 423ee57de2d9619f11115d73

@@ -228,8 +259,8 @@ internal fun <D : Query.Data> ApolloCall<D>.watchInternal(data: D?): Flow<Apollo

val ApolloClient.apolloStore: ApolloStore
get() {
return interceptors.firstOrNull { it is ApolloCacheInterceptor }?.let {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this no longer works, and should be cacheInterceptor (but then it must be made public)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but then it must be made public

I have made it public

Comment on lines 117 to 123
return chain.proceed(request).map { response ->
response.newBuilder().cacheHeaders(CacheHeaders.Builder().addHeader(ApolloCacheHeaders.DO_NOT_STORE, "").build()).build()
}
return chain.proceed(
request.newBuilder()
.cacheHeaders(
CacheHeaders.Builder().addHeader(ApolloCacheHeaders.DO_NOT_STORE, "").build()
)
.build()
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yet another good side effect IMO.

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.

👍

@martinbonnin martinbonnin merged commit 1a9918a into main Apr 8, 2025
8 checks passed
@martinbonnin martinbonnin deleted the fixed-interceptors branch April 8, 2025 16:15
BoD pushed a commit that referenced this pull request Apr 8, 2025
* Add cacheInterceptor() and autoPersistedQueriesInterceptor()

* make cacheInterceptor public

* add mention in the changelog

* remove obsolete tests

* update the test to include patching based on the response

* update README

(cherry picked from commit 1a9918a)
BoD added a commit that referenced this pull request Apr 8, 2025
…6456)

* Add cacheInterceptor() and autoPersistedQueriesInterceptor()

* make cacheInterceptor public

* add mention in the changelog

* remove obsolete tests

* update the test to include patching based on the response

* update README

(cherry picked from commit 1a9918a)

Co-authored-by: Martin Bonnin <martin@mbonnin.net>
@martinbonnin martinbonnin mentioned this pull request Apr 29, 2025
5 tasks
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.

4 participants