You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/advanced/network-connectivity.mdx
+12-31Lines changed: 12 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,11 +2,6 @@
2
2
title: Monitor the network state to reduce latency
3
3
---
4
4
5
-
<ExperimentalFeature>
6
-
7
-
**Network Monitor APIs are currently [experimental](https://www.apollographql.com/docs/resources/product-launch-stages/#experimental-features) in Apollo Kotlin.** If you have feedback on them, please let us know via [GitHub issues](https://github.com/apollographql/apollo-kotlin/issues/new?assignees=&labels=Type%3A+Bug&template=bug_report.md) or in the [Kotlin Slack community](https://slack.kotl.in/).
8
-
9
-
</ExperimentalFeature>
10
5
11
6
Android and Apple targets provide APIs to monitor the network state of your device:
12
7
@@ -40,6 +35,7 @@ When a `NetworkMonitor` is configured, you can use `failFastIfOffline` to avoid
@@ -57,35 +53,20 @@ When a `NetworkMonitor` is configured, `retryOnError` uses `NetworkMonitor.waitF
57
53
58
54
### Customizing the retry algorithm
59
55
60
-
You can customize the retry algorithm further by defining your own interceptor:
56
+
To customize the retry algorithm, use a `RetryStrategy`. The following example shows a `RetryStrategy` that uses exponential backoff and gives up after four tries:
Copy file name to clipboardExpand all lines: libraries/apollo-api/api/apollo-api.klib.api
+4Lines changed: 4 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1183,6 +1183,10 @@ final class com.apollographql.apollo.exception/ApolloNetworkException : com.apol
1183
1183
final fun <get-platformCause>(): kotlin/Any? // com.apollographql.apollo.exception/ApolloNetworkException.platformCause.<get-platformCause>|<get-platformCause>(){}[0]
1184
1184
}
1185
1185
1186
+
final class com.apollographql.apollo.exception/ApolloOfflineException : com.apollographql.apollo.exception/ApolloException { // com.apollographql.apollo.exception/ApolloOfflineException|null[0]
final class com.apollographql.apollo.exception/ApolloParseException : com.apollographql.apollo.exception/ApolloException { // com.apollographql.apollo.exception/ApolloParseException|null[0]
Copy file name to clipboardExpand all lines: libraries/apollo-runtime/api/android/apollo-runtime.api
+13Lines changed: 13 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -142,6 +142,7 @@ public final class com/apollographql/apollo/ApolloClient$Builder : com/apollogra
142
142
public final fun networkTransport (Lcom/apollographql/apollo/network/NetworkTransport;)Lcom/apollographql/apollo/ApolloClient$Builder;
143
143
public final fun removeHttpInterceptor (Lcom/apollographql/apollo/network/http/HttpInterceptor;)Lcom/apollographql/apollo/ApolloClient$Builder;
144
144
public final fun removeInterceptor (Lcom/apollographql/apollo/interceptor/ApolloInterceptor;)Lcom/apollographql/apollo/ApolloClient$Builder;
145
+
public final fun retryOnError (Ljava/lang/Boolean;)Lcom/apollographql/apollo/ApolloClient$Builder;
145
146
public final fun retryOnError (Lkotlin/jvm/functions/Function1;)Lcom/apollographql/apollo/ApolloClient$Builder;
146
147
public final fun retryOnErrorInterceptor (Lcom/apollographql/apollo/interceptor/ApolloInterceptor;)Lcom/apollographql/apollo/ApolloClient$Builder;
147
148
public fun sendApqExtensions (Ljava/lang/Boolean;)Lcom/apollographql/apollo/ApolloClient$Builder;
@@ -232,6 +233,18 @@ public final class com/apollographql/apollo/interceptor/AutoPersistedQueryInterc
232
233
233
234
public final class com/apollographql/apollo/interceptor/RetryOnErrorInterceptorKt {
234
235
public static final fun RetryOnErrorInterceptor (Lcom/apollographql/apollo/network/NetworkMonitor;)Lcom/apollographql/apollo/interceptor/ApolloInterceptor;
236
+
public static final fun RetryOnErrorInterceptor (Lcom/apollographql/apollo/network/NetworkMonitor;Lcom/apollographql/apollo/interceptor/RetryStrategy;)Lcom/apollographql/apollo/interceptor/ApolloInterceptor;
237
+
}
238
+
239
+
public final class com/apollographql/apollo/interceptor/RetryState {
240
+
public fun <init> (Lcom/apollographql/apollo/network/NetworkMonitor;)V
241
+
public final fun getAttempt ()I
242
+
public final fun getNetworkMonitor ()Lcom/apollographql/apollo/network/NetworkMonitor;
243
+
public final fun setAttempt (I)V
244
+
}
245
+
246
+
public abstract interface class com/apollographql/apollo/interceptor/RetryStrategy {
247
+
public abstract fun shouldRetry (Lcom/apollographql/apollo/interceptor/RetryState;Lcom/apollographql/apollo/api/ApolloRequest;Lcom/apollographql/apollo/api/ApolloResponse;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
235
248
}
236
249
237
250
public final class com/apollographql/apollo/network/IncrementalDeliveryProtocol : java/lang/Enum {
Copy file name to clipboardExpand all lines: libraries/apollo-runtime/api/apollo-runtime.klib.api
+17Lines changed: 17 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -32,6 +32,10 @@ final enum class com.apollographql.apollo.network/IncrementalDeliveryProtocol :
32
32
final fun values(): kotlin/Array<com.apollographql.apollo.network/IncrementalDeliveryProtocol> // com.apollographql.apollo.network/IncrementalDeliveryProtocol.values|values#static(){}[0]
33
33
}
34
34
35
+
abstract fun interface com.apollographql.apollo.interceptor/RetryStrategy { // com.apollographql.apollo.interceptor/RetryStrategy|null[0]
36
+
abstract suspend fun shouldRetry(com.apollographql.apollo.interceptor/RetryState, com.apollographql.apollo.api/ApolloRequest<*>, com.apollographql.apollo.api/ApolloResponse<*>): kotlin/Boolean // com.apollographql.apollo.interceptor/RetryStrategy.shouldRetry|shouldRetry(com.apollographql.apollo.interceptor.RetryState;com.apollographql.apollo.api.ApolloRequest<*>;com.apollographql.apollo.api.ApolloResponse<*>){}[0]
final val networkMonitor // com.apollographql.apollo.interceptor/RetryState.networkMonitor|{}networkMonitor[0]
238
+
final fun <get-networkMonitor>(): com.apollographql.apollo.network/NetworkMonitor? // com.apollographql.apollo.interceptor/RetryState.networkMonitor.<get-networkMonitor>|<get-networkMonitor>(){}[0]
239
+
240
+
final var attempt // com.apollographql.apollo.interceptor/RetryState.attempt|{}attempt[0]
241
+
final fun <get-attempt>(): kotlin/Int // com.apollographql.apollo.interceptor/RetryState.attempt.<get-attempt>|<get-attempt>(){}[0]
242
+
final fun <set-attempt>(kotlin/Int) // com.apollographql.apollo.interceptor/RetryState.attempt.<set-attempt>|<set-attempt>(kotlin.Int){}[0]
243
+
}
244
+
230
245
final class com.apollographql.apollo.network.http/ApolloClientAwarenessInterceptor : com.apollographql.apollo.network.http/HttpInterceptor { // com.apollographql.apollo.network.http/ApolloClientAwarenessInterceptor|null[0]
@@ -701,6 +716,7 @@ final class com.apollographql.apollo/ApolloClient : com.apollographql.apollo.api
701
716
final fun networkTransport(com.apollographql.apollo.network/NetworkTransport?): com.apollographql.apollo/ApolloClient.Builder // com.apollographql.apollo/ApolloClient.Builder.networkTransport|networkTransport(com.apollographql.apollo.network.NetworkTransport?){}[0]
702
717
final fun removeHttpInterceptor(com.apollographql.apollo.network.http/HttpInterceptor): com.apollographql.apollo/ApolloClient.Builder // com.apollographql.apollo/ApolloClient.Builder.removeHttpInterceptor|removeHttpInterceptor(com.apollographql.apollo.network.http.HttpInterceptor){}[0]
703
718
final fun removeInterceptor(com.apollographql.apollo.interceptor/ApolloInterceptor): com.apollographql.apollo/ApolloClient.Builder // com.apollographql.apollo/ApolloClient.Builder.removeInterceptor|removeInterceptor(com.apollographql.apollo.interceptor.ApolloInterceptor){}[0]
719
+
final fun retryOnError(kotlin/Boolean?): com.apollographql.apollo/ApolloClient.Builder // com.apollographql.apollo/ApolloClient.Builder.retryOnError|retryOnError(kotlin.Boolean?){}[0]
704
720
final fun retryOnError(kotlin/Function1<com.apollographql.apollo.api/ApolloRequest<*>, kotlin/Boolean>?): com.apollographql.apollo/ApolloClient.Builder // com.apollographql.apollo/ApolloClient.Builder.retryOnError|retryOnError(kotlin.Function1<com.apollographql.apollo.api.ApolloRequest<*>,kotlin.Boolean>?){}[0]
705
721
final fun retryOnErrorInterceptor(com.apollographql.apollo.interceptor/ApolloInterceptor?): com.apollographql.apollo/ApolloClient.Builder // com.apollographql.apollo/ApolloClient.Builder.retryOnErrorInterceptor|retryOnErrorInterceptor(com.apollographql.apollo.interceptor.ApolloInterceptor?){}[0]
706
722
final fun sendApqExtensions(kotlin/Boolean?): com.apollographql.apollo/ApolloClient.Builder // com.apollographql.apollo/ApolloClient.Builder.sendApqExtensions|sendApqExtensions(kotlin.Boolean?){}[0]
@@ -787,6 +803,7 @@ final fun (com.apollographql.apollo.network/NetworkTransport).com.apollographql.
787
803
final fun (com.apollographql.apollo.network/NetworkTransport).com.apollographql.apollo.network.ws/closeConnection(kotlin/Throwable) // com.apollographql.apollo.network.ws/closeConnection|closeConnection@com.apollographql.apollo.network.NetworkTransport(kotlin.Throwable){}[0]
788
804
final fun <#A: kotlin/Any?> (com.apollographql.apollo.api/MutableExecutionOptions<#A>).com.apollographql.apollo/conflateFetchPolicyInterceptorResponses(kotlin/Boolean): #A // com.apollographql.apollo/conflateFetchPolicyInterceptorResponses|conflateFetchPolicyInterceptorResponses@com.apollographql.apollo.api.MutableExecutionOptions<0:0>(kotlin.Boolean){0§<kotlin.Any?>}[0]
789
805
final fun com.apollographql.apollo.interceptor/RetryOnErrorInterceptor(com.apollographql.apollo.network/NetworkMonitor): com.apollographql.apollo.interceptor/ApolloInterceptor // com.apollographql.apollo.interceptor/RetryOnErrorInterceptor|RetryOnErrorInterceptor(com.apollographql.apollo.network.NetworkMonitor){}[0]
806
+
final fun com.apollographql.apollo.interceptor/RetryOnErrorInterceptor(com.apollographql.apollo.network/NetworkMonitor, com.apollographql.apollo.interceptor/RetryStrategy): com.apollographql.apollo.interceptor/ApolloInterceptor // com.apollographql.apollo.interceptor/RetryOnErrorInterceptor|RetryOnErrorInterceptor(com.apollographql.apollo.network.NetworkMonitor;com.apollographql.apollo.interceptor.RetryStrategy){}[0]
790
807
final fun com.apollographql.apollo.network.http/DefaultHttpEngine(kotlin/Long = ...): com.apollographql.apollo.network.http/HttpEngine // com.apollographql.apollo.network.http/DefaultHttpEngine|DefaultHttpEngine(kotlin.Long){}[0]
791
808
final fun com.apollographql.apollo.network.websocket/WebSocketEngine(): com.apollographql.apollo.network.websocket/WebSocketEngine // com.apollographql.apollo.network.websocket/WebSocketEngine|WebSocketEngine(){}[0]
Copy file name to clipboardExpand all lines: libraries/apollo-runtime/api/jvm/apollo-runtime.api
+13Lines changed: 13 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -142,6 +142,7 @@ public final class com/apollographql/apollo/ApolloClient$Builder : com/apollogra
142
142
public final fun networkTransport (Lcom/apollographql/apollo/network/NetworkTransport;)Lcom/apollographql/apollo/ApolloClient$Builder;
143
143
public final fun removeHttpInterceptor (Lcom/apollographql/apollo/network/http/HttpInterceptor;)Lcom/apollographql/apollo/ApolloClient$Builder;
144
144
public final fun removeInterceptor (Lcom/apollographql/apollo/interceptor/ApolloInterceptor;)Lcom/apollographql/apollo/ApolloClient$Builder;
145
+
public final fun retryOnError (Ljava/lang/Boolean;)Lcom/apollographql/apollo/ApolloClient$Builder;
145
146
public final fun retryOnError (Lkotlin/jvm/functions/Function1;)Lcom/apollographql/apollo/ApolloClient$Builder;
146
147
public final fun retryOnErrorInterceptor (Lcom/apollographql/apollo/interceptor/ApolloInterceptor;)Lcom/apollographql/apollo/ApolloClient$Builder;
147
148
public fun sendApqExtensions (Ljava/lang/Boolean;)Lcom/apollographql/apollo/ApolloClient$Builder;
@@ -232,6 +233,18 @@ public final class com/apollographql/apollo/interceptor/AutoPersistedQueryInterc
232
233
233
234
public final class com/apollographql/apollo/interceptor/RetryOnErrorInterceptorKt {
234
235
public static final fun RetryOnErrorInterceptor (Lcom/apollographql/apollo/network/NetworkMonitor;)Lcom/apollographql/apollo/interceptor/ApolloInterceptor;
236
+
public static final fun RetryOnErrorInterceptor (Lcom/apollographql/apollo/network/NetworkMonitor;Lcom/apollographql/apollo/interceptor/RetryStrategy;)Lcom/apollographql/apollo/interceptor/ApolloInterceptor;
237
+
}
238
+
239
+
public final class com/apollographql/apollo/interceptor/RetryState {
240
+
public fun <init> (Lcom/apollographql/apollo/network/NetworkMonitor;)V
241
+
public final fun getAttempt ()I
242
+
public final fun getNetworkMonitor ()Lcom/apollographql/apollo/network/NetworkMonitor;
243
+
public final fun setAttempt (I)V
244
+
}
245
+
246
+
public abstract interface class com/apollographql/apollo/interceptor/RetryStrategy {
247
+
public abstract fun shouldRetry (Lcom/apollographql/apollo/interceptor/RetryState;Lcom/apollographql/apollo/api/ApolloRequest;Lcom/apollographql/apollo/api/ApolloResponse;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
235
248
}
236
249
237
250
public final class com/apollographql/apollo/network/IncrementalDeliveryProtocol : java/lang/Enum {
@@ -144,7 +142,6 @@ class ApolloCall<D : Operation.Data> internal constructor(
144
142
*
145
143
* The returned [Flow] has [kotlinx.coroutines.channels.Channel.UNLIMITED] buffering so that no response is missed in the case of a slow consumer. Use [kotlinx.coroutines.flow.buffer] to change that behaviour.
146
144
*
147
-
* @see toFlowV3
148
145
* @see ApolloClient.Builder.dispatcher
149
146
*/
150
147
funtoFlow(): Flow<ApolloResponse<D>> {
@@ -178,7 +175,6 @@ class ApolloCall<D : Operation.Data> internal constructor(
178
175
*
179
176
* @throws ApolloException if the call returns zero or multiple valid GraphQL responses.
0 commit comments