Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions app/src/main/java/guide/graphql/toc/data/Apollo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ import com.apollographql.apollo.ApolloClient
import com.apollographql.apollo.cache.normalized.lru.EvictionPolicy
import com.apollographql.apollo.cache.normalized.lru.LruNormalizedCacheFactory

val cacheFactory =
LruNormalizedCacheFactory(EvictionPolicy.builder().maxSizeBytes(10 * 1024 * 1024).build())
object Apollo {

val apolloClient: ApolloClient = ApolloClient.builder()
.serverUrl("https://api.graphql.guide/graphql")
.normalizedCache(cacheFactory)
.build()
val client: ApolloClient by lazy {
val cacheFactory =
LruNormalizedCacheFactory(EvictionPolicy.builder().maxSizeBytes(10 * 1024 * 1024).build())

ApolloClient.builder()
.serverUrl("https://api.graphql.guide/graphql")
.normalizedCache(cacheFactory)
.build()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import com.apollographql.apollo.exception.ApolloException
import com.google.android.material.transition.MaterialSharedAxis
import guide.graphql.toc.ChaptersQuery
import guide.graphql.toc.R
import guide.graphql.toc.data.apolloClient
import guide.graphql.toc.data.Apollo
import guide.graphql.toc.databinding.ChaptersFragmentBinding

class ChaptersFragment : Fragment() {
Expand Down Expand Up @@ -73,7 +73,7 @@ class ChaptersFragment : Fragment() {

lifecycleScope.launchWhenStarted {
try {
val response = apolloClient.query(
val response = Apollo.client.query(
ChaptersQuery()
).toDeferred().await()
if (response.hasErrors()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import com.apollographql.apollo.coroutines.toDeferred
import com.apollographql.apollo.exception.ApolloException
import com.google.android.material.transition.MaterialSharedAxis
import guide.graphql.toc.SectionsQuery
import guide.graphql.toc.data.apolloClient
import guide.graphql.toc.data.Apollo
import guide.graphql.toc.databinding.SectionsFragmentBinding

class SectionsFragment : Fragment() {
Expand Down Expand Up @@ -66,7 +66,7 @@ class SectionsFragment : Fragment() {
binding.spinner.visibility = View.VISIBLE
binding.error.visibility = View.GONE
try {
val response = apolloClient.query(
val response = Apollo.client.query(
SectionsQuery(id = args.chapterId)
).toDeferred().await()

Expand Down