-
Notifications
You must be signed in to change notification settings - Fork 0
/
GraphModule.kt
45 lines (39 loc) · 1.38 KB
/
GraphModule.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package io.tohure.graphqlwithdaggerkotlin.di.module
import com.apollographql.apollo.ApolloClient
import dagger.Module
import dagger.Provides
import io.tohure.graphqlwithdaggerkotlin.BuildConfig
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import java.util.concurrent.TimeUnit
import javax.inject.Singleton
/**
* Created by tohure on 2/03/18.
*/
@Module
class GraphModule {
@Provides
@Singleton
fun provideInterceptor(): HttpLoggingInterceptor =
HttpLoggingInterceptor()
.setLevel(if (BuildConfig.DEBUG)
HttpLoggingInterceptor.Level.BODY
else
HttpLoggingInterceptor.Level.NONE)
@Provides
@Singleton
fun provideOkHttpClient(httpLoggingInterceptor: HttpLoggingInterceptor): OkHttpClient =
OkHttpClient.Builder()
.addInterceptor(httpLoggingInterceptor)
.writeTimeout(10, TimeUnit.SECONDS)
.connectTimeout(10, TimeUnit.SECONDS)
.readTimeout(10, TimeUnit.SECONDS)
.build()
@Provides
@Singleton
fun provideApolloClient(okHttpClient: OkHttpClient): ApolloClient =
ApolloClient.builder()
.serverUrl(BuildConfig.BASE_URL)
.okHttpClient(okHttpClient)
.build()
}