Last active
March 12, 2019 22:03
-
-
Save johngorithm/fb42ba2eb7c9dfc80c743eff4f0eab99 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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