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/migration/5.0.mdx
+99Lines changed: 99 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -126,6 +126,105 @@ query GetUser {
126
126
You can read more in the ["handling nullability" page](https://www.apollographql.com/docs/kotlin/advanced/nullability).
127
127
128
128
129
+
## `apollo-runtime`
130
+
131
+
### New WebSockets
132
+
133
+
In Apollo Kotlin 5, the websocket code has been rewritten to simplify it and clarify the error and retry semantics.
134
+
135
+
All the classes in the `com.apollographql.apollo.network.ws` package have been deprecated and a new implementation is available in `com.apollographql.apollo.network.websocket`.
136
+
137
+
To migrate, replace all your instances of `com.apollographql.apollo.network.ws` with `com.apollographql.apollo.network.websocket`:
Some shorthand methods on `ApolloClient.Builder` have been deprecated and replaced by explicit configuration. In those cases, you can use `subscriptionNetworkTransport` directly.
150
+
151
+
For an example, you can replace `ApolloClient.Builder.webSocketEngine()` like so:
152
+
153
+
```kotlin
154
+
// Replace
155
+
ApolloClient.Builder()
156
+
.webSocketEngine(webSocketEngine)
157
+
.build()
158
+
// With
159
+
ApolloClient.Builder()
160
+
.subscriptionNetworkTransport(
161
+
WebSocketNetworkTransport.Builder()
162
+
.webSocketEngine(webSocketEngine)
163
+
.build()
164
+
)
165
+
.build()
166
+
```
167
+
168
+
The default WebSocket protocol has changed to [graphql-ws](https://github.com/enisdenjo/graphql-ws/blob/master/PROTOCOL.md).
169
+
170
+
If you were already using it before, you'll now need to create the `subscriptionNetworkTransport()` explicitely:
171
+
172
+
```kotlin
173
+
// Replace
174
+
val apolloClient =ApolloClient.Builder()
175
+
.protocol(GraphQLWsProtocol.Factory())
176
+
.build()
177
+
178
+
// With
179
+
val apolloClient =ApolloClient.Builder()
180
+
.subscriptionNetworkTransport(
181
+
WebSocketNetworkTransport.Builder()
182
+
.serverUrl(url)
183
+
.wsProtocol(GraphQLWsProtocol())
184
+
.build()
185
+
)
186
+
.build()
187
+
188
+
```
189
+
190
+
If you are still relying on [the (now deprecated) transport](https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md), you can use `SubscriptionWsProtocol`:
191
+
192
+
```kotlin
193
+
val apolloClient =ApolloClient.Builder()
194
+
.subscriptionNetworkTransport(
195
+
WebSocketNetworkTransport.Builder()
196
+
.serverUrl(url)
197
+
.wsProtocol(SubscriptionsWsProtocol())
198
+
.build()
199
+
)
200
+
.build()
201
+
```
202
+
203
+
The retry management is now moved to `retryOnErrorInterceptor`:
if (context.request.operation isSubscription<*>) {
220
+
delay(2.0.pow(attempt.toDouble()).toLong())
221
+
true
222
+
} else {
223
+
false
224
+
}
225
+
})
226
+
```
227
+
129
228
## `apollo-http-cache`
130
229
131
230
`apollo-http-cache` is now deprecated. Instead, it uses the existing OkHttp cache using [cacheUrlOverride](https://square.github.io/okhttp/5.x/okhttp/okhttp3/-request/-builder/cache-url-override.html).
Copy file name to clipboardExpand all lines: libraries/apollo-engine-tests/src/commonMain/kotlin/com/apollographql/apollo/engine/tests/WebSocketEngineTest.kt
Copy file name to clipboardExpand all lines: libraries/apollo-runtime/api/android/apollo-runtime.api
+17-8Lines changed: 17 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -231,20 +231,25 @@ public final class com/apollographql/apollo/interceptor/AutoPersistedQueryInterc
231
231
public final class com/apollographql/apollo/interceptor/AutoPersistedQueryInterceptor$Companion {
232
232
}
233
233
234
+
public final class com/apollographql/apollo/interceptor/RetryContext {
235
+
public fun <init> (Lcom/apollographql/apollo/network/NetworkMonitor;Lcom/apollographql/apollo/api/ApolloRequest;)V
236
+
public final fun getAttempt ()I
237
+
public final fun getNetworkMonitor ()Lcom/apollographql/apollo/network/NetworkMonitor;
238
+
public final fun getRequest ()Lcom/apollographql/apollo/api/ApolloRequest;
239
+
public final fun getResponse ()Lcom/apollographql/apollo/api/ApolloResponse;
240
+
public final fun resetAttempt ()V
241
+
}
242
+
234
243
public final class com/apollographql/apollo/interceptor/RetryOnErrorInterceptorKt {
244
+
public static final fun RetryOnErrorInterceptor ()Lcom/apollographql/apollo/interceptor/ApolloInterceptor;
235
245
public static final fun RetryOnErrorInterceptor (Lcom/apollographql/apollo/network/NetworkMonitor;)Lcom/apollographql/apollo/interceptor/ApolloInterceptor;
236
246
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
247
+
public static synthetic fun RetryOnErrorInterceptor$default (Lcom/apollographql/apollo/network/NetworkMonitor;Lcom/apollographql/apollo/interceptor/RetryStrategy;ILjava/lang/Object;)Lcom/apollographql/apollo/interceptor/ApolloInterceptor;
248
+
public static final fun getDefaultRetryStrategy ()Lcom/apollographql/apollo/interceptor/RetryStrategy;
244
249
}
245
250
246
251
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;
252
+
public abstract fun shouldRetry (Lcom/apollographql/apollo/interceptor/RetryContext;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
248
253
}
249
254
250
255
public final class com/apollographql/apollo/network/IncrementalDeliveryProtocol : java/lang/Enum {
@@ -538,6 +543,7 @@ public abstract interface class com/apollographql/apollo/network/websocket/WebSo
538
543
}
539
544
540
545
public final class com/apollographql/apollo/network/websocket/WebSocketEngine_jvmKt {
546
+
public static final fun DefaultWebSocketEngine (Lokhttp3/WebSocket$Factory;)Lcom/apollographql/apollo/network/websocket/WebSocketEngine;
541
547
public static final fun WebSocketEngine ()Lcom/apollographql/apollo/network/websocket/WebSocketEngine;
542
548
public static final fun WebSocketEngine (Lkotlin/jvm/functions/Function0;)Lcom/apollographql/apollo/network/websocket/WebSocketEngine;
543
549
public static final fun WebSocketEngine (Lokhttp3/WebSocket$Factory;)Lcom/apollographql/apollo/network/websocket/WebSocketEngine;
@@ -556,16 +562,19 @@ public final class com/apollographql/apollo/network/websocket/WebSocketNetworkTr
556
562
public final fun closeConnection (Lcom/apollographql/apollo/exception/ApolloException;)V
557
563
public fun dispose ()V
558
564
public fun execute (Lcom/apollographql/apollo/api/ApolloRequest;)Lkotlinx/coroutines/flow/Flow;
565
+
public final fun getSubscriptionCount ()Lkotlinx/coroutines/flow/StateFlow;
559
566
}
560
567
561
568
public final class com/apollographql/apollo/network/websocket/WebSocketNetworkTransport$Builder {
562
569
public fun <init> ()V
563
570
public final fun build ()Lcom/apollographql/apollo/network/websocket/WebSocketNetworkTransport;
564
571
public final fun connectionAcknowledgeTimeout-BwNAW2A (Lkotlin/time/Duration;)Lcom/apollographql/apollo/network/websocket/WebSocketNetworkTransport$Builder;
565
572
public final fun idleTimeout-BwNAW2A (Lkotlin/time/Duration;)Lcom/apollographql/apollo/network/websocket/WebSocketNetworkTransport$Builder;
573
+
public final fun idleTimeoutMillis (Ljava/lang/Long;)Lcom/apollographql/apollo/network/websocket/WebSocketNetworkTransport$Builder;
566
574
public final fun incrementalDeliveryProtocol (Lcom/apollographql/apollo/network/IncrementalDeliveryProtocol;)Lcom/apollographql/apollo/network/websocket/WebSocketNetworkTransport$Builder;
567
575
public final fun parserFactory (Lcom/apollographql/apollo/network/websocket/SubscriptionParserFactory;)Lcom/apollographql/apollo/network/websocket/WebSocketNetworkTransport$Builder;
568
576
public final fun pingInterval-BwNAW2A (Lkotlin/time/Duration;)Lcom/apollographql/apollo/network/websocket/WebSocketNetworkTransport$Builder;
577
+
public final fun protocol (Lcom/apollographql/apollo/network/websocket/WsProtocol;)Lcom/apollographql/apollo/network/websocket/WebSocketNetworkTransport$Builder;
569
578
public final fun serverUrl (Ljava/lang/String;)Lcom/apollographql/apollo/network/websocket/WebSocketNetworkTransport$Builder;
570
579
public final fun webSocketEngine (Lcom/apollographql/apollo/network/websocket/WebSocketEngine;)Lcom/apollographql/apollo/network/websocket/WebSocketNetworkTransport$Builder;
571
580
public final fun wsProtocol (Lcom/apollographql/apollo/network/websocket/WsProtocol;)Lcom/apollographql/apollo/network/websocket/WebSocketNetworkTransport$Builder;
0 commit comments