File tree Expand file tree Collapse file tree 3 files changed +15
-10
lines changed
app/src/main/java/guide/graphql/toc Expand file tree Collapse file tree 3 files changed +15
-10
lines changed Original file line number Diff line number Diff line change @@ -4,10 +4,15 @@ import com.apollographql.apollo.ApolloClient
4
4
import com.apollographql.apollo.cache.normalized.lru.EvictionPolicy
5
5
import com.apollographql.apollo.cache.normalized.lru.LruNormalizedCacheFactory
6
6
7
- val cacheFactory =
8
- LruNormalizedCacheFactory (EvictionPolicy .builder().maxSizeBytes(10 * 1024 * 1024 ).build())
7
+ object Apollo {
9
8
10
- val apolloClient: ApolloClient = ApolloClient .builder()
11
- .serverUrl(" https://api.graphql.guide/graphql" )
12
- .normalizedCache(cacheFactory)
13
- .build()
9
+ val client: ApolloClient by lazy {
10
+ val cacheFactory =
11
+ LruNormalizedCacheFactory (EvictionPolicy .builder().maxSizeBytes(10 * 1024 * 1024 ).build())
12
+
13
+ ApolloClient .builder()
14
+ .serverUrl(" https://api.graphql.guide/graphql" )
15
+ .normalizedCache(cacheFactory)
16
+ .build()
17
+ }
18
+ }
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ import com.apollographql.apollo.exception.ApolloException
15
15
import com.google.android.material.transition.MaterialSharedAxis
16
16
import guide.graphql.toc.ChaptersQuery
17
17
import guide.graphql.toc.R
18
- import guide.graphql.toc.data.apolloClient
18
+ import guide.graphql.toc.data.Apollo
19
19
import guide.graphql.toc.databinding.ChaptersFragmentBinding
20
20
21
21
class ChaptersFragment : Fragment () {
@@ -73,7 +73,7 @@ class ChaptersFragment : Fragment() {
73
73
74
74
lifecycleScope.launchWhenStarted {
75
75
try {
76
- val response = apolloClient .query(
76
+ val response = Apollo .client .query(
77
77
ChaptersQuery ()
78
78
).toDeferred().await()
79
79
if (response.hasErrors()) {
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ import com.apollographql.apollo.coroutines.toDeferred
13
13
import com.apollographql.apollo.exception.ApolloException
14
14
import com.google.android.material.transition.MaterialSharedAxis
15
15
import guide.graphql.toc.SectionsQuery
16
- import guide.graphql.toc.data.apolloClient
16
+ import guide.graphql.toc.data.Apollo
17
17
import guide.graphql.toc.databinding.SectionsFragmentBinding
18
18
19
19
class SectionsFragment : Fragment () {
@@ -66,7 +66,7 @@ class SectionsFragment : Fragment() {
66
66
binding.spinner.visibility = View .VISIBLE
67
67
binding.error.visibility = View .GONE
68
68
try {
69
- val response = apolloClient .query(
69
+ val response = Apollo .client .query(
70
70
SectionsQuery (id = args.chapterId)
71
71
).toDeferred().await()
72
72
You can’t perform that action at this time.
0 commit comments