Last active
April 6, 2019 07:40
-
-
Save Lavanyagaur22/2ca4699609461b546579e3810638e563 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
fun getApolloClient(context: Context): ApolloClient? { | |
val apolloSqlHelper = ApolloSqlHelper(context, SQL_CACHE_NAME) | |
//Used Normalized Disk Cache: Per node caching of responses in SQL. | |
//Persists normalized responses on disk so that they can used after process death. | |
val cacheFactory = LruNormalizedCacheFactory( | |
EvictionPolicy.NO_EVICTION, SqlNormalizedCacheFactory(apolloSqlHelper) | |
) | |
//If Apollo Client is not null, return it else make a new Apollo Client. | |
//Helps in singleton pattern. | |
apClient?.let { | |
return it | |
} ?: kotlin.run { | |
apClient = ApolloClient.builder() | |
.okHttpClient(getOkhttpClient(context)!!) | |
.normalizedCache(cacheFactory, cacheResolver()) | |
.serverUrl(BASE_URL) | |
.build() | |
} | |
return apClient | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment