3

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();
nandha-dev
  • 153
  • 1
  • 3
  • 11

1 Answers1

2

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))
Sylvain
  • 21
  • 3
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 17 '23 at 07:16