Skip to content

Instantly share code, notes, and snippets.

@johngorithm
Last active March 12, 2019 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johngorithm/fb42ba2eb7c9dfc80c743eff4f0eab99 to your computer and use it in GitHub Desktop.
Save johngorithm/fb42ba2eb7c9dfc80c743eff4f0eab99 to your computer and use it in GitHub Desktop.
package com.jxw.graphql.service;
//in: app/src/main/java/packageDir/service/
import com.apollographql.apollo.ApolloClient;
import com.jxw.graphql.app.DemoApplication;
import com.jxw.graphql.type.CustomType;
import com.jxw.graphql.utils.CustomDateAdapter;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
public class ApiService {
/**
* private constructor.
* Utility class
*/
private ApiService() {
}
/**
* Returns the Apollo Client instance.
* @return ApolloClient
*/
public static ApolloClient getApolloClient(DemoApplication application) {
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.addInterceptor(loggingInterceptor)
.build();
return ApolloClient.builder()
.serverUrl(application.getBaseUrl())
.okHttpClient(okHttpClient)
.addCustomTypeAdapter(CustomType.DATETIME, new CustomDateAdapter())
.build();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment