android 无法将OkHttp客户端添加到Apollo客户端(Apollo-kotin版本3)

hc8w905p  于 2023-06-20  发布在  Android
关注(0)|答案(1)|浏览(104)

我无法将我的Okhttp客户端连接到Apollo客户端。在ApolloClient.Builder类中找不到okhttpclient()方法。它显示“Cannot resolve method 'okHttpClient' in 'Builder'”错误。我用的是阿波罗3号。
build.gradle(项目)

classpath "com.apollographql.apollo3:apollo-gradle-plugin:3.6.1"

build.gradle(App)

// Graphql
def apollo3GraphqlVersion = '3.6.1'
implementation "com.apollographql.apollo3:apollo-runtime:$apollo3GraphqlVersion"
implementation "com.apollographql.apollo3:apollo-rx3-support:$apollo3GraphqlVersion"

Client.class

apolloClient = new ApolloClient.Builder()
    .serverUrl(baseUrl)
    .okHttpClient() // error "Cannot resolve method 'okHttpClient' in 'Builder'"
    .build();
x6yk4ghg

x6yk4ghg1#

虽然有点晚,但我找到了一种方法来做到这一点(版本3.8.2):

import com.apollographql.apollo3.ApolloClient
import com.apollographql.apollo3.network.http.DefaultHttpEngine;

apolloClient = new ApolloClient.Builder()
    .serverUrl("")
    .httpEngine(new DefaultHttpEngine(okHttpClient))

相关问题