Skip to content

Commit c01f353

Browse files
authored
Merge pull request #1553 from joreilly/use-incubating-cache-0.0.8
Use Apollo Normalized Cache incubating v0.0.8
2 parents 1684517 + 7aea96c commit c01f353

File tree

3 files changed

+5
-23
lines changed

3 files changed

+5
-23
lines changed

gradle/libs.versions.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ activity-compose = "1.10.1"
1212
androidx-lifecycle = "2.8.7"
1313
androidx-datastore = "1.1.3"
1414
apollo = "4.1.1"
15-
apollo-cache = "0.0.6"
15+
apollo-cache = "0.0.8"
1616
compose = "1.7.8"
1717
composeLifecyleRuntime="2.8.4"
1818
compose-multiplatform = "1.7.3"

shared/src/commonMain/kotlin/dev/johnoreilly/confetti/ApolloClientCache.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import com.apollographql.apollo.network.NetworkMonitor
1616
import com.apollographql.cache.normalized.api.CacheControlCacheResolver
1717
import com.apollographql.cache.normalized.api.SchemaCoordinatesMaxAgeProvider
1818
import com.apollographql.cache.normalized.maxStale
19-
import com.apollographql.cache.normalized.storeReceiveDate
19+
import com.apollographql.cache.normalized.storeReceivedDate
2020
import dev.johnoreilly.confetti.cache.Cache
2121
import dev.johnoreilly.confetti.di.getNormalizedCacheFactory
2222
import dev.johnoreilly.confetti.utils.registerApolloDebugServer
@@ -132,7 +132,7 @@ class ApolloClientCache : KoinComponent {
132132
)
133133
),
134134
)
135-
.storeReceiveDate(true)
135+
.storeReceivedDate(true)
136136
.maxStale(Duration.INFINITE)
137137
.autoPersistedQueries()
138138
.addInterceptor(tokenProviderInterceptor)

shared/src/commonMain/kotlin/dev/johnoreilly/confetti/fetchPolicy.kt

+2-20
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import com.apollographql.apollo.api.ApolloRequest
44
import com.apollographql.apollo.api.ApolloResponse
55
import com.apollographql.apollo.api.MutableExecutionOptions
66
import com.apollographql.apollo.api.Operation
7-
import com.apollographql.apollo.exception.ApolloException
87
import com.apollographql.apollo.interceptor.ApolloInterceptor
98
import com.apollographql.apollo.interceptor.ApolloInterceptorChain
109
import com.apollographql.cache.normalized.FetchPolicy
1110
import com.apollographql.cache.normalized.cacheInfo
11+
import com.apollographql.cache.normalized.errorsAsException
1212
import com.apollographql.cache.normalized.fetchFromCache
1313
import com.apollographql.cache.normalized.fetchPolicy
1414
import com.apollographql.cache.normalized.fetchPolicyInterceptor
@@ -53,29 +53,11 @@ private object CacheFirstInterceptor : ApolloInterceptor {
5353
if (networkResponse.exception == null || !first) {
5454
networkResponse
5555
} else {
56-
cacheResponse.cacheMissAsException()
56+
cacheResponse.errorsAsException()
5757
}
5858
)
5959
first = false
6060
}
6161
}
6262
}
6363
}
64-
65-
private fun <D : Operation.Data> ApolloResponse<D>.cacheMissAsException(): ApolloResponse<D> {
66-
return if (cacheInfo!!.isCacheHit) {
67-
this
68-
} else {
69-
val cacheMissException =
70-
errors.orEmpty().mapNotNull { it.extensions?.get("exception") as? ApolloException }.reduceOrNull { acc, e ->
71-
acc.addSuppressed(e)
72-
acc
73-
}
74-
newBuilder()
75-
.exception(cacheMissException)
76-
.data(null)
77-
.errors(null)
78-
.build()
79-
}
80-
}
81-

0 commit comments

Comments
 (0)