https://kotlinlang.org logo
Title
t

Tower Guidev2

08/24/2021, 11:53 AM
Hello, Im investigating
Apollo3
on Android
// Replace
val response = apolloClient.query(query)
                      .toBuilder()
                      .responseFetcher(ApolloResponseFetchers.CACHE_FIRST)
                      .build()
                      .await()

// With
val request = ApolloRequest(query).withFetchPolicy(CacheFirst)
val response = apolloClient.query(request)
I cannot see/use function
withFetchPolicy
what am I doing wrong?
my gradle resembles this
api 'com.apollographql.apollo3:apollo-runtime:3.0.0-alpha03'
api 'com.apollographql.apollo3:apollo-api:3.0.0-alpha03'
with plugin this
plugins {
    id "com.android.library"
    id "kotlin-android"
    id "kotlin-kapt"
    id 'org.jetbrains.kotlin.plugin.serialization' version '1.4.20'
    id 'dagger.hilt.android.plugin'
    id 'com.apollographql.apollo3' version '3.0.0-alpha03'
}
m

mbonnin

08/24/2021, 12:01 PM
Hi again 👋 ! That was fast 😃
You'll need to add
apollo-normalized-cache
to your dependencies
withFetchPolicy
is an extension function defined in this artifact
t

Tower Guidev2

08/24/2021, 12:05 PM
😄
when using apollo2 I see these HTTP Headers including cache (
X-APOLLO-CACHE-FETCH-STRATEGY
)
I/okhttp.OkHttpClient: --> POST <https://rickandmortyapi.com/graphql>
I/okhttp.OkHttpClient: Content-Length: 360
I/okhttp.OkHttpClient: Content-Type: application/json
I/okhttp.OkHttpClient: Accept: application/json
I/okhttp.OkHttpClient: X-APOLLO-OPERATION-ID: adce3b369f8f6e372a2b01fc227d31ec3d312e86580a2833cd3bd732b5d186f9
I/okhttp.OkHttpClient: X-APOLLO-OPERATION-NAME: LocationAttempt
I/okhttp.OkHttpClient: X-APOLLO-CACHE-KEY: fe3283fbe04b4979510c54491afdc796
I/okhttp.OkHttpClient: X-APOLLO-CACHE-FETCH-STRATEGY: NETWORK_ONLY
I/okhttp.OkHttpClient: X-APOLLO-EXPIRE-TIMEOUT: 0
I/okhttp.OkHttpClient: X-APOLLO-EXPIRE-AFTER-READ: false
I/okhttp.OkHttpClient: X-APOLLO-PREFETCH: false
I/okhttp.OkHttpClient: X-APOLLO-CACHE-DO-NOT-STORE: false
I/okhttp.OkHttpClient: traceparent: 00-8b080467e95d488cbdc242236f6cf8ec--00
I/okhttp.OkHttpClient: tracestate: @nr=0-2-2693137-1444013261-----1629808125837
However when I switch to Apollo3 I dont see the same HTTP headers, is that anything to be concerned about?
m

mbonnin

08/24/2021, 12:39 PM
I don't think this is a problem. HTTP doesn't need to know about cache by default and it saves a few bytes for each query
If you need additional headers, you can add them with
withHttpHeaders()
t

Tower Guidev2

08/24/2021, 12:41 PM
ok, I'll relax 😉
☺️ 1
😎 1