From 5a22b131f7a5a59718863d59226c0ad40a281871 Mon Sep 17 00:00:00 2001 From: Matt Creaser Date: Thu, 14 Nov 2024 12:26:43 -0400 Subject: [PATCH] Fix using Apollo to connect to AppSync in China --- .../amplifyframework/apollo/appsync/AppSyncEndpoint.kt | 2 +- .../apollo/appsync/AppSyncEndpointTest.kt | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/apollo/apollo-appsync/src/main/java/com/amplifyframework/apollo/appsync/AppSyncEndpoint.kt b/apollo/apollo-appsync/src/main/java/com/amplifyframework/apollo/appsync/AppSyncEndpoint.kt index ca66eb30c..bf89778f2 100644 --- a/apollo/apollo-appsync/src/main/java/com/amplifyframework/apollo/appsync/AppSyncEndpoint.kt +++ b/apollo/apollo-appsync/src/main/java/com/amplifyframework/apollo/appsync/AppSyncEndpoint.kt @@ -21,7 +21,7 @@ import java.net.URL import okhttp3.HttpUrl.Companion.toHttpUrlOrNull private val standardEndpointRegex = - "^https://\\w{26}\\.appsync-api\\.\\w{2}(?:-\\w{2,})+-\\d\\.amazonaws.com/graphql$".toRegex() + "^https://\\w{26}\\.appsync-api\\.\\w{2}(?:-\\w{2,})+-\\d\\.amazonaws.com(?:\\.cn)?/graphql$".toRegex() /** * Class representing the AppSync endpoint. There are multiple URLs associated with each AppSync endpoint: the diff --git a/apollo/apollo-appsync/src/test/java/com/amplifyframework/apollo/appsync/AppSyncEndpointTest.kt b/apollo/apollo-appsync/src/test/java/com/amplifyframework/apollo/appsync/AppSyncEndpointTest.kt index c9109d2f2..e93b1bfc8 100644 --- a/apollo/apollo-appsync/src/test/java/com/amplifyframework/apollo/appsync/AppSyncEndpointTest.kt +++ b/apollo/apollo-appsync/src/test/java/com/amplifyframework/apollo/appsync/AppSyncEndpointTest.kt @@ -26,6 +26,8 @@ import org.junit.Test class AppSyncEndpointTest { private val standardAppSyncUrl = "https://example1234567890123456789.appsync-api.us-east-1.amazonaws.com/graphql" + private val standardAppSyncUrlChina = + "https://example1234567890123456789.appsync-api.us-east-1.amazonaws.com.cn/graphql" private val customAppSyncUrl = "https://api.example.com/graphql" @Test @@ -48,6 +50,13 @@ class AppSyncEndpointTest { "https://example1234567890123456789.appsync-realtime-api.us-east-1.amazonaws.com/graphql/connect" } + @Test + fun `uses expected realtime URL for standard endpoint in China`() { + val endpoint = AppSyncEndpoint(standardAppSyncUrlChina) + endpoint.websocketConnection.toString() shouldBe + "https://example1234567890123456789.appsync-realtime-api.us-east-1.amazonaws.com.cn/graphql/connect" + } + @Test fun `uses expected realtime URL for custom endpoint`() { val endpoint = AppSyncEndpoint(customAppSyncUrl)