Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd7b7aed

Browse files
martinbonninBoD
andauthored
Promote experimental websockets to stable (#6774)
* Promote experimental websockets to stable* AI code review* Update docs/source/migration/5.0.mdxCo-authored-by: Benoit 'BoD' Lubek <BoD@JRAF.org>* Update libraries/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo/interceptor/RetryOnErrorInterceptor.ktCo-authored-by: Benoit 'BoD' Lubek <BoD@JRAF.org>* Update wording---------Co-authored-by: Benoit 'BoD' Lubek <BoD@JRAF.org>
1 parent37a07cf commitd7b7aed

File tree

44 files changed

+501
-395
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+501
-395
lines changed

‎docs/source/migration/5.0.mdx‎

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,105 @@ query GetUser {
126126
You can read more in the["handling nullability" page](https://www.apollographql.com/docs/kotlin/advanced/nullability).
127127

128128

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`:
138+
139+
```kotlin
140+
// Replace
141+
importcom.apollographql.apollo.network.ws.AppSyncWsProtocol
142+
importcom.apollographql.apollo.network.ws.WebSocketNetworkTransport
143+
144+
// With
145+
importcom.apollographql.apollo.network.websocket.AppSyncWsProtocol
146+
importcom.apollographql.apollo.network.websocket.WebSocketNetworkTransport
147+
```
148+
149+
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()` as follows:
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 may remove the call to`protocol()` or define it explicitly using`subscriptionNetworkTransport()`:
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`:
204+
205+
```kotlin
206+
// Replace
207+
val apolloClient=ApolloClient.Builder()
208+
.webSocketServerUrl("http://localhost:8080/subscriptions")
209+
.webSocketReopenWhen { e, attempt->
210+
delay(2.0.pow(attempt.toDouble()).toLong())
211+
// retry after the delay
212+
true
213+
}
214+
215+
// With
216+
val apolloClient=ApolloClient.Builder()
217+
.webSocketServerUrl("http://localhost:8080/subscriptions")
218+
.retryOnErrorInterceptor(RetryOnErrorInterceptor { context->
219+
if (context.request.operationisSubscription<*>) {
220+
delay(2.0.pow(context.attempt.toDouble()).toLong())
221+
true
222+
}else {
223+
false
224+
}
225+
})
226+
```
227+
129228
##`apollo-http-cache`
130229

131230
`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).

‎libraries/apollo-engine-tests/src/commonMain/kotlin/com/apollographql/apollo/engine/tests/WebSocketEngineTest.kt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@file:Suppress("DEPRECATION")
12
packagecom.apollographql.apollo.engine.tests
23

34
importcom.apollographql.apollo.annotations.ApolloInternal

‎libraries/apollo-engine-tests/src/commonMain/kotlin/com/apollographql/apollo/engine/tests/all-tests.kt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@file:Suppress("DEPRECATION")
12
packagecom.apollographql.apollo.engine.tests
23

34
importcom.apollographql.apollo.annotations.ApolloInternal

‎libraries/apollo-engine-tests/src/commonTest/kotlin/AllTests.kt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@file:Suppress("DEPRECATION")
2+
13
importcom.apollographql.apollo.engine.tests.Platform
24
importcom.apollographql.apollo.engine.tests.platform
35
importcom.apollographql.apollo.engine.tests.runAllTests

‎libraries/apollo-runtime/api/android/apollo-runtime.api‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -231,20 +231,25 @@ public final class com/apollographql/apollo/interceptor/AutoPersistedQueryInterc
231231
public final class com/apollographql/apollo/interceptor/AutoPersistedQueryInterceptor$Companion {
232232
}
233233

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+
234243
public final class com/apollographql/apollo/interceptor/RetryOnErrorInterceptorKt {
244+
public static final fun RetryOnErrorInterceptor ()Lcom/apollographql/apollo/interceptor/ApolloInterceptor;
235245
public static final fun RetryOnErrorInterceptor (Lcom/apollographql/apollo/network/NetworkMonitor;)Lcom/apollographql/apollo/interceptor/ApolloInterceptor;
236246
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;
244249
}
245250

246251
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;
248253
}
249254

250255
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
538543
}
539544

540545
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;
541547
public static final fun WebSocketEngine ()Lcom/apollographql/apollo/network/websocket/WebSocketEngine;
542548
public static final fun WebSocketEngine (Lkotlin/jvm/functions/Function0;)Lcom/apollographql/apollo/network/websocket/WebSocketEngine;
543549
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
556562
public final fun closeConnection (Lcom/apollographql/apollo/exception/ApolloException;)V
557563
public fun dispose ()V
558564
public fun execute (Lcom/apollographql/apollo/api/ApolloRequest;)Lkotlinx/coroutines/flow/Flow;
565+
public final fun getSubscriptionCount ()Lkotlinx/coroutines/flow/StateFlow;
559566
}
560567

561568
public final class com/apollographql/apollo/network/websocket/WebSocketNetworkTransport$Builder {
562569
public fun <init> ()V
563570
public final fun build ()Lcom/apollographql/apollo/network/websocket/WebSocketNetworkTransport;
564571
public final fun connectionAcknowledgeTimeout-BwNAW2A (Lkotlin/time/Duration;)Lcom/apollographql/apollo/network/websocket/WebSocketNetworkTransport$Builder;
565572
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;
566574
public final fun incrementalDeliveryProtocol (Lcom/apollographql/apollo/network/IncrementalDeliveryProtocol;)Lcom/apollographql/apollo/network/websocket/WebSocketNetworkTransport$Builder;
567575
public final fun parserFactory (Lcom/apollographql/apollo/network/websocket/SubscriptionParserFactory;)Lcom/apollographql/apollo/network/websocket/WebSocketNetworkTransport$Builder;
568576
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;
569578
public final fun serverUrl (Ljava/lang/String;)Lcom/apollographql/apollo/network/websocket/WebSocketNetworkTransport$Builder;
570579
public final fun webSocketEngine (Lcom/apollographql/apollo/network/websocket/WebSocketEngine;)Lcom/apollographql/apollo/network/websocket/WebSocketNetworkTransport$Builder;
571580
public final fun wsProtocol (Lcom/apollographql/apollo/network/websocket/WsProtocol;)Lcom/apollographql/apollo/network/websocket/WebSocketNetworkTransport$Builder;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp