Skip to content

Commit 2723e54

Browse files
committed
Don't deprecate FetchPolicy after all (except CacheAndNetwork)
1 parent 4359ff9 commit 2723e54

8 files changed

Lines changed: 141 additions & 164 deletions

File tree

normalized-cache/api/normalized-cache.api

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ public abstract interface class com/apollographql/cache/normalized/CacheOptions
132132
public abstract fun allowCachedPartialResults (Z)V
133133
public abstract fun noCache (Z)V
134134
public abstract fun onlyIfCached (Z)V
135-
public abstract fun reload (Z)V
136135
}
137136

138137
public final class com/apollographql/cache/normalized/ErrorExtensionsKt {
@@ -153,11 +152,8 @@ public final class com/apollographql/cache/normalized/FetchPolicy : java/lang/En
153152
public final class com/apollographql/cache/normalized/FetchPolicyInterceptors {
154153
public static final fun errorsAsException (Lcom/apollographql/apollo/api/ApolloResponse;)Lcom/apollographql/apollo/api/ApolloResponse;
155154
public static final fun getCacheAndNetworkInterceptor ()Lcom/apollographql/apollo/interceptor/ApolloInterceptor;
156-
public static final fun getCacheFirstInterceptor ()Lcom/apollographql/apollo/interceptor/ApolloInterceptor;
157-
public static final fun getCacheOnlyInterceptor ()Lcom/apollographql/apollo/interceptor/ApolloInterceptor;
158155
public static final fun getDefaultFetchPolicyInterceptor ()Lcom/apollographql/apollo/interceptor/ApolloInterceptor;
159156
public static final fun getNetworkFirstInterceptor ()Lcom/apollographql/apollo/interceptor/ApolloInterceptor;
160-
public static final fun getNetworkOnlyInterceptor ()Lcom/apollographql/apollo/interceptor/ApolloInterceptor;
161157
}
162158

163159
public final class com/apollographql/cache/normalized/GarbageCollectResult {
@@ -226,7 +222,6 @@ public final class com/apollographql/cache/normalized/NormalizedCache {
226222
public static final fun refetchCacheOptions (Lcom/apollographql/apollo/api/MutableExecutionOptions;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
227223
public static final fun refetchPolicy (Lcom/apollographql/apollo/api/MutableExecutionOptions;Lcom/apollographql/cache/normalized/FetchPolicy;)Ljava/lang/Object;
228224
public static final fun refetchPolicyInterceptor (Lcom/apollographql/apollo/api/MutableExecutionOptions;Lcom/apollographql/apollo/interceptor/ApolloInterceptor;)Ljava/lang/Object;
229-
public static final fun reload (Lcom/apollographql/apollo/api/MutableExecutionOptions;Z)Ljava/lang/Object;
230225
public static final fun storeExpirationDate (Lcom/apollographql/apollo/api/MutableExecutionOptions;Z)Ljava/lang/Object;
231226
public static final fun storePartialResponses (Lcom/apollographql/apollo/api/MutableExecutionOptions;Z)Ljava/lang/Void;
232227
public static final fun storeReceivedDate (Lcom/apollographql/apollo/api/MutableExecutionOptions;Z)Ljava/lang/Object;

normalized-cache/api/normalized-cache.klib.api

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ abstract interface com.apollographql.cache.normalized/CacheOptions { // com.apol
118118
abstract fun allowCachedPartialResults(kotlin/Boolean) // com.apollographql.cache.normalized/CacheOptions.allowCachedPartialResults|allowCachedPartialResults(kotlin.Boolean){}[0]
119119
abstract fun noCache(kotlin/Boolean) // com.apollographql.cache.normalized/CacheOptions.noCache|noCache(kotlin.Boolean){}[0]
120120
abstract fun onlyIfCached(kotlin/Boolean) // com.apollographql.cache.normalized/CacheOptions.onlyIfCached|onlyIfCached(kotlin.Boolean){}[0]
121-
abstract fun reload(kotlin/Boolean) // com.apollographql.cache.normalized/CacheOptions.reload|reload(kotlin.Boolean){}[0]
122121
}
123122

124123
sealed interface com.apollographql.cache.normalized.api/MaxAge { // com.apollographql.cache.normalized.api/MaxAge|null[0]
@@ -596,16 +595,10 @@ final val com.apollographql.cache.normalized.api/TypePolicyCacheKeyGenerator //
596595
final fun <get-TypePolicyCacheKeyGenerator>(): com.apollographql.cache.normalized.api/CacheKeyGenerator // com.apollographql.cache.normalized.api/TypePolicyCacheKeyGenerator.<get-TypePolicyCacheKeyGenerator>|<get-TypePolicyCacheKeyGenerator>(){}[0]
597596
final val com.apollographql.cache.normalized/CacheAndNetworkInterceptor // com.apollographql.cache.normalized/CacheAndNetworkInterceptor|{}CacheAndNetworkInterceptor[0]
598597
final fun <get-CacheAndNetworkInterceptor>(): com.apollographql.apollo.interceptor/ApolloInterceptor // com.apollographql.cache.normalized/CacheAndNetworkInterceptor.<get-CacheAndNetworkInterceptor>|<get-CacheAndNetworkInterceptor>(){}[0]
599-
final val com.apollographql.cache.normalized/CacheFirstInterceptor // com.apollographql.cache.normalized/CacheFirstInterceptor|{}CacheFirstInterceptor[0]
600-
final fun <get-CacheFirstInterceptor>(): com.apollographql.apollo.interceptor/ApolloInterceptor // com.apollographql.cache.normalized/CacheFirstInterceptor.<get-CacheFirstInterceptor>|<get-CacheFirstInterceptor>(){}[0]
601-
final val com.apollographql.cache.normalized/CacheOnlyInterceptor // com.apollographql.cache.normalized/CacheOnlyInterceptor|{}CacheOnlyInterceptor[0]
602-
final fun <get-CacheOnlyInterceptor>(): com.apollographql.apollo.interceptor/ApolloInterceptor // com.apollographql.cache.normalized/CacheOnlyInterceptor.<get-CacheOnlyInterceptor>|<get-CacheOnlyInterceptor>(){}[0]
603598
final val com.apollographql.cache.normalized/DefaultFetchPolicyInterceptor // com.apollographql.cache.normalized/DefaultFetchPolicyInterceptor|{}DefaultFetchPolicyInterceptor[0]
604599
final fun <get-DefaultFetchPolicyInterceptor>(): com.apollographql.apollo.interceptor/ApolloInterceptor // com.apollographql.cache.normalized/DefaultFetchPolicyInterceptor.<get-DefaultFetchPolicyInterceptor>|<get-DefaultFetchPolicyInterceptor>(){}[0]
605600
final val com.apollographql.cache.normalized/NetworkFirstInterceptor // com.apollographql.cache.normalized/NetworkFirstInterceptor|{}NetworkFirstInterceptor[0]
606601
final fun <get-NetworkFirstInterceptor>(): com.apollographql.apollo.interceptor/ApolloInterceptor // com.apollographql.cache.normalized/NetworkFirstInterceptor.<get-NetworkFirstInterceptor>|<get-NetworkFirstInterceptor>(){}[0]
607-
final val com.apollographql.cache.normalized/NetworkOnlyInterceptor // com.apollographql.cache.normalized/NetworkOnlyInterceptor|{}NetworkOnlyInterceptor[0]
608-
final fun <get-NetworkOnlyInterceptor>(): com.apollographql.apollo.interceptor/ApolloInterceptor // com.apollographql.cache.normalized/NetworkOnlyInterceptor.<get-NetworkOnlyInterceptor>|<get-NetworkOnlyInterceptor>(){}[0]
609602
final val com.apollographql.cache.normalized/VERSION // com.apollographql.cache.normalized/VERSION|{}VERSION[0]
610603
final fun <get-VERSION>(): kotlin/String // com.apollographql.cache.normalized/VERSION.<get-VERSION>|<get-VERSION>(){}[0]
611604
final val com.apollographql.cache.normalized/apolloStore // com.apollographql.cache.normalized/apolloStore|@com.apollographql.apollo.ApolloClient{}apolloStore[0]
@@ -657,7 +650,6 @@ final fun <#A: kotlin/Any?> (com.apollographql.apollo.api/MutableExecutionOption
657650
final fun <#A: kotlin/Any?> (com.apollographql.apollo.api/MutableExecutionOptions<#A>).com.apollographql.cache.normalized/refetchCacheOptions(kotlin/Function1<com.apollographql.cache.normalized/CacheOptions, kotlin/Unit>): #A // com.apollographql.cache.normalized/refetchCacheOptions|refetchCacheOptions@com.apollographql.apollo.api.MutableExecutionOptions<0:0>(kotlin.Function1<com.apollographql.cache.normalized.CacheOptions,kotlin.Unit>){0§<kotlin.Any?>}[0]
658651
final fun <#A: kotlin/Any?> (com.apollographql.apollo.api/MutableExecutionOptions<#A>).com.apollographql.cache.normalized/refetchPolicy(com.apollographql.cache.normalized/FetchPolicy): #A // com.apollographql.cache.normalized/refetchPolicy|refetchPolicy@com.apollographql.apollo.api.MutableExecutionOptions<0:0>(com.apollographql.cache.normalized.FetchPolicy){0§<kotlin.Any?>}[0]
659652
final fun <#A: kotlin/Any?> (com.apollographql.apollo.api/MutableExecutionOptions<#A>).com.apollographql.cache.normalized/refetchPolicyInterceptor(com.apollographql.apollo.interceptor/ApolloInterceptor): #A // com.apollographql.cache.normalized/refetchPolicyInterceptor|refetchPolicyInterceptor@com.apollographql.apollo.api.MutableExecutionOptions<0:0>(com.apollographql.apollo.interceptor.ApolloInterceptor){0§<kotlin.Any?>}[0]
660-
final fun <#A: kotlin/Any?> (com.apollographql.apollo.api/MutableExecutionOptions<#A>).com.apollographql.cache.normalized/reload(kotlin/Boolean): #A // com.apollographql.cache.normalized/reload|reload@com.apollographql.apollo.api.MutableExecutionOptions<0:0>(kotlin.Boolean){0§<kotlin.Any?>}[0]
661653
final fun <#A: kotlin/Any?> (com.apollographql.apollo.api/MutableExecutionOptions<#A>).com.apollographql.cache.normalized/storeExpirationDate(kotlin/Boolean): #A // com.apollographql.cache.normalized/storeExpirationDate|storeExpirationDate@com.apollographql.apollo.api.MutableExecutionOptions<0:0>(kotlin.Boolean){0§<kotlin.Any?>}[0]
662654
final fun <#A: kotlin/Any?> (com.apollographql.apollo.api/MutableExecutionOptions<#A>).com.apollographql.cache.normalized/storePartialResponses(kotlin/Boolean): kotlin/Nothing // com.apollographql.cache.normalized/storePartialResponses|storePartialResponses@com.apollographql.apollo.api.MutableExecutionOptions<0:0>(kotlin.Boolean){0§<kotlin.Any?>}[0]
663655
final fun <#A: kotlin/Any?> (com.apollographql.apollo.api/MutableExecutionOptions<#A>).com.apollographql.cache.normalized/storeReceivedDate(kotlin/Boolean): #A // com.apollographql.cache.normalized/storeReceivedDate|storeReceivedDate@com.apollographql.apollo.api.MutableExecutionOptions<0:0>(kotlin.Boolean){0§<kotlin.Any?>}[0]

normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/CacheOptions.kt

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,32 @@ package com.apollographql.cache.normalized
33
interface CacheOptions {
44
fun noCache(noCache: Boolean)
55
fun onlyIfCached(onlyIfCached: Boolean)
6-
fun reload(reload: Boolean)
76
fun allowCachedPartialResults(allowCachedPartialResults: Boolean)
87
fun allowCachedErrors(allowCachedErrors: Boolean)
98
}
109

1110
internal data class CacheOptionsImpl(
1211
var noCache: Boolean = false,
1312
var onlyIfCached: Boolean = false,
14-
var reload: Boolean = false,
1513
var allowCachedPartialResults: Boolean = false,
1614
var allowCachedErrors: Boolean = false,
1715
) : CacheOptions {
1816
override fun noCache(noCache: Boolean) {
17+
// noCache and onlyIfCached are mutually exclusive
1918
if (noCache) {
20-
// noCache and onlyIfCached are mutually exclusive
2119
onlyIfCached = false
2220
}
2321
this.noCache = noCache
2422
}
2523

2624
override fun onlyIfCached(onlyIfCached: Boolean) {
25+
// noCache and onlyIfCached are mutually exclusive
2726
if (onlyIfCached) {
28-
// noCache and onlyIfCached are mutually exclusive
2927
noCache = false
30-
// reload and onlyIfCached are mutually exclusive
31-
reload = false
3228
}
3329
this.onlyIfCached = onlyIfCached
3430
}
3531

36-
override fun reload(reload: Boolean) {
37-
if (reload) {
38-
// onlyIfCached and reload are mutually exclusive
39-
onlyIfCached = false
40-
}
41-
this.reload = reload
42-
}
43-
4432
override fun allowCachedPartialResults(allowCachedPartialResults: Boolean) {
4533
this.allowCachedPartialResults = allowCachedPartialResults
4634
}

normalized-cache/src/commonMain/kotlin/com/apollographql/cache/normalized/ClientCacheExtensions.kt

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import com.apollographql.apollo.api.Operation
1515
import com.apollographql.apollo.api.Query
1616
import com.apollographql.apollo.api.http.get
1717
import com.apollographql.apollo.exception.ApolloException
18+
import com.apollographql.apollo.exception.ApolloGraphQLException
1819
import com.apollographql.apollo.exception.CacheMissException
1920
import com.apollographql.apollo.interceptor.ApolloInterceptor
2021
import com.apollographql.apollo.interceptor.ApolloInterceptorChain
@@ -259,7 +260,6 @@ fun <D : Query.Data> ApolloCall<D>.watch(): Flow<ApolloResponse<D>> {
259260
copy().fetchPolicyInterceptor(refetchPolicyInterceptor)
260261
.noCache(refetchNoCache)
261262
.onlyIfCached(refetchOnlyIfCached)
262-
.reload(refetchReload)
263263
.allowCachedPartialResults(refetchAllowCachedPartialResults)
264264
.allowCachedErrors(refetchAllowCachedErrors)
265265
.watchInternal(response?.data)
@@ -304,48 +304,54 @@ val ApolloClient.apolloStore: ApolloStore
304304
* Sets the initial [FetchPolicy]
305305
* This only has effects for queries. Mutations and subscriptions always use the network only.
306306
*/
307-
@Deprecated("Use noCache(), onlyIfCached() or reload() instead. For NetworkFirst, use fetchPolicyInterceptor(NetworkFirstInterceptor) instead")
308-
@Suppress("DEPRECATION", "UNCHECKED_CAST")
307+
@Suppress("UNCHECKED_CAST")
309308
fun <T> MutableExecutionOptions<T>.fetchPolicy(fetchPolicy: FetchPolicy): T {
310309
// Reset first
311310
onlyIfCached(false)
312311
noCache(false)
313-
reload(false)
314312
return when (fetchPolicy) {
315313
FetchPolicy.NetworkFirst -> {
316-
// NetworkFirst is deprecated but should still work
317314
fetchPolicyInterceptor(NetworkFirstInterceptor)
318315
}
319316

320317
FetchPolicy.CacheOnly -> onlyIfCached(true)
321318
FetchPolicy.NetworkOnly -> noCache(true)
322319
FetchPolicy.CacheFirst -> this as T
323-
FetchPolicy.CacheAndNetwork -> reload(true)
320+
@Suppress("DEPRECATION")
321+
FetchPolicy.CacheAndNetwork,
322+
-> {
323+
// CacheAndNetwork is deprecated but should still work
324+
@Suppress("DEPRECATION")
325+
fetchPolicyInterceptor(CacheAndNetworkInterceptor)
326+
}
324327
}
325328
}
326329

327330
/**
328331
* Sets the [FetchPolicy] used when watching queries and a cache change has been published
329332
*/
330-
@Deprecated("Use refetchCacheOptions() instead. For NetworkFirst, use refetchPolicyInterceptor(NetworkFirstInterceptor) instead")
331-
@Suppress("DEPRECATION", "UNCHECKED_CAST")
332-
fun <T> MutableExecutionOptions<T>.refetchPolicy(@Suppress("DEPRECATION") fetchPolicy: FetchPolicy): T {
333+
@Suppress("UNCHECKED_CAST")
334+
fun <T> MutableExecutionOptions<T>.refetchPolicy(fetchPolicy: FetchPolicy): T {
333335
// Reset first
334336
refetchCacheOptions {
335337
onlyIfCached(true)
336338
noCache(false)
337-
reload(false)
338339
}
339340
return when (fetchPolicy) {
340341
FetchPolicy.NetworkFirst -> {
341-
// NetworkFirst is deprecated but should still work
342342
refetchPolicyInterceptor(NetworkFirstInterceptor)
343343
}
344344

345345
FetchPolicy.CacheOnly -> refetchCacheOptions { onlyIfCached(true) }
346346
FetchPolicy.NetworkOnly -> refetchCacheOptions { noCache(true) }
347347
FetchPolicy.CacheFirst -> this as T
348-
FetchPolicy.CacheAndNetwork -> refetchCacheOptions { reload(true) }
348+
@Suppress("DEPRECATION")
349+
FetchPolicy.CacheAndNetwork,
350+
-> {
351+
// CacheAndNetwork is deprecated but should still work
352+
@Suppress("DEPRECATION")
353+
refetchPolicyInterceptor(CacheAndNetworkInterceptor)
354+
}
349355
}
350356
}
351357

@@ -789,6 +795,12 @@ internal class FetchAllowCachedPartialResultsContext(val value: Boolean) : Execu
789795
internal val ExecutionOptions.allowCachedPartialResults: Boolean
790796
get() = executionContext[FetchAllowCachedPartialResultsContext]?.value ?: false
791797

798+
/**
799+
* Sets whether to allow partial results to be returned from the cache.
800+
* If set to false, if any field is missing in the cache, the returned response will have a null data and a non-null exception of type [CacheMissException].
801+
*
802+
* Default: false
803+
*/
792804
fun <T> MutableExecutionOptions<T>.allowCachedPartialResults(allowCachedPartialResults: Boolean): T =
793805
addExecutionContext(FetchAllowCachedPartialResultsContext(allowCachedPartialResults))
794806

@@ -800,6 +812,12 @@ internal class FetchAllowCachedErrorsContext(val value: Boolean) : ExecutionCont
800812
companion object Key : ExecutionContext.Key<FetchAllowCachedErrorsContext>
801813
}
802814

815+
/**
816+
* Sets whether to allow GraphQL errors to be returned from the cache.
817+
* If set to false, if any field is an Error in the cache, the returned response will have a null data and a non-null exception of type [ApolloGraphQLException].
818+
*
819+
* Default: false
820+
*/
803821
internal val ExecutionOptions.allowCachedErrors: Boolean
804822
get() = executionContext[FetchAllowCachedErrorsContext]?.value ?: false
805823

@@ -814,12 +832,18 @@ internal class FetchNoCacheContext(val value: Boolean) : ExecutionContext.Elemen
814832
companion object Key : ExecutionContext.Key<FetchNoCacheContext>
815833
}
816834

835+
/**
836+
* Sets whether to skip the cache.
837+
* If set to true, the cache will not be queried at all.
838+
*
839+
* Default: false
840+
*/
817841
internal val ExecutionOptions.noCache: Boolean
818842
get() = executionContext[FetchNoCacheContext]?.value ?: false
819843

820844
fun <T> MutableExecutionOptions<T>.noCache(noCache: Boolean): T {
845+
// noCache and onlyIfCached are mutually exclusive
821846
if (noCache) {
822-
// noCache and onlyIfCached are mutually exclusive
823847
addExecutionContext(FetchOnlyIfCachedContext(false))
824848
}
825849
return addExecutionContext(FetchNoCacheContext(noCache))
@@ -836,36 +860,21 @@ internal class FetchOnlyIfCachedContext(val value: Boolean) : ExecutionContext.E
836860
internal val ExecutionOptions.onlyIfCached: Boolean
837861
get() = executionContext[FetchOnlyIfCachedContext]?.value ?: false
838862

863+
/**
864+
* Sets whether to only return results from the cache.
865+
* If set to true, the network will not be queried at all.
866+
*
867+
* Default: false
868+
*/
839869
fun <T> MutableExecutionOptions<T>.onlyIfCached(onlyIfCached: Boolean): T {
870+
// noCache and onlyIfCached are mutually exclusive
840871
if (onlyIfCached) {
841-
// noCache and onlyIfCached are mutually exclusive
842872
addExecutionContext(FetchNoCacheContext(false))
843-
// reload and onlyIfCached are mutually exclusive
844-
addExecutionContext(FetchReloadContext(false))
845873
}
846874
return addExecutionContext(FetchOnlyIfCachedContext(onlyIfCached))
847875
}
848876

849877

850-
internal class FetchReloadContext(val value: Boolean) : ExecutionContext.Element {
851-
override val key: ExecutionContext.Key<*>
852-
get() = Key
853-
854-
companion object Key : ExecutionContext.Key<FetchReloadContext>
855-
}
856-
857-
internal val ExecutionOptions.reload: Boolean
858-
get() = executionContext[FetchReloadContext]?.value ?: false
859-
860-
fun <T> MutableExecutionOptions<T>.reload(reload: Boolean): T {
861-
if (reload) {
862-
// onlyIfCached and reload are mutually exclusive
863-
addExecutionContext(FetchOnlyIfCachedContext(false))
864-
}
865-
return addExecutionContext(FetchReloadContext(reload))
866-
}
867-
868-
869878
internal class RefetchAllowCachedPartialResultsContext(val value: Boolean) : ExecutionContext.Element {
870879
override val key: ExecutionContext.Key<*>
871880
get() = Key
@@ -909,22 +918,13 @@ internal class RefetchOnlyIfCachedContext(val value: Boolean) : ExecutionContext
909918
internal val ExecutionOptions.refetchOnlyIfCached: Boolean
910919
get() = executionContext[RefetchOnlyIfCachedContext]?.value ?: true
911920

912-
913-
internal class RefetchReloadContext(val value: Boolean) : ExecutionContext.Element {
914-
override val key: ExecutionContext.Key<*>
915-
get() = Key
916-
917-
companion object Key : ExecutionContext.Key<RefetchReloadContext>
918-
}
919-
920-
internal val ExecutionOptions.refetchReload: Boolean
921-
get() = executionContext[RefetchReloadContext]?.value ?: false
922-
921+
/**
922+
* Sets the cache options used when watching queries and a cache change has been published.
923+
*/
923924
fun <T> MutableExecutionOptions<T>.refetchCacheOptions(refetchCacheOptions: CacheOptions.() -> Unit): T {
924925
val refetchCacheOptions = CacheOptionsImpl().also { refetchCacheOptions(it) }
925926
addExecutionContext(RefetchNoCacheContext(refetchCacheOptions.noCache))
926927
addExecutionContext(RefetchOnlyIfCachedContext(refetchCacheOptions.onlyIfCached))
927-
addExecutionContext(RefetchReloadContext(refetchCacheOptions.reload))
928928
addExecutionContext(RefetchAllowCachedPartialResultsContext(refetchCacheOptions.allowCachedPartialResults))
929929
return addExecutionContext(RefetchAllowCachedErrorsContext(refetchCacheOptions.allowCachedErrors))
930930
}

0 commit comments

Comments
 (0)