Not able to add OkHttp client to Apollo Client (Apollo-kotin Version 3)

330 Views Asked by At

I am not able to attach my Okhttp client to Apollo client. I can't able to find okhttpclient() method in ApolloClient.Builder class. It shows "Cannot resolve method 'okHttpClient' in 'Builder'" error. I'm using apollo version 3.

build.gradle (Project)

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();
1

There are 1 best solutions below

1
Sylvain On

It's a bit late but I found a way to do this (version 3.8.2) :

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

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