Skip to content

Commit 5016f36

Browse files
authored
fix(API): Fixing issue with CN endpoints (aws-amplify#3941)
1 parent 2a17a77 commit 5016f36

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

AmplifyPlugins/API/Sources/AWSAPIPlugin/SubscriptionFactory/AppSyncRealTimeClientFactory.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ extension AppSyncRealTimeClientFactory {
136136
return url
137137
}
138138

139-
guard host.hasSuffix("amazonaws.com") else {
139+
guard host.hasSuffix("amazonaws.com") || host.hasSuffix("amazonaws.com.cn") else {
140140
return url.appendingPathComponent("realtime")
141141
}
142142

@@ -163,7 +163,7 @@ extension AppSyncRealTimeClientFactory {
163163
return url
164164
}
165165

166-
guard host.hasSuffix("amazonaws.com") else {
166+
guard host.hasSuffix("amazonaws.com") || host.hasSuffix("amazonaws.com.cn") else {
167167
if url.lastPathComponent == "realtime" {
168168
return url.deletingLastPathComponent()
169169
}

AmplifyPlugins/API/Tests/AWSAPIPluginTests/SubscriptionFactory/AppSyncRealTimeClientFactoryTests.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ class AppSyncRealTimeClientFactoryTests: XCTestCase {
1717
AppSyncRealTimeClientFactory.appSyncRealTimeEndpoint(appSyncEndpoint),
1818
URL(string: "wss://abc.appsync-realtime-api.amazonaws.com/graphql")
1919
)
20+
21+
let appSyncEndpointCN = URL(string: "https://abc.appsync-api.amazonaws.com.cn/graphql")!
22+
XCTAssertEqual(
23+
AppSyncRealTimeClientFactory.appSyncRealTimeEndpoint(appSyncEndpointCN),
24+
URL(string: "wss://abc.appsync-realtime-api.amazonaws.com.cn/graphql")
25+
)
2026
}
2127

2228
func testAppSyncRealTimeEndpoint_withAWSAppSyncRealTimeDomain_returnTheSameDomain() {
@@ -25,6 +31,12 @@ class AppSyncRealTimeClientFactoryTests: XCTestCase {
2531
AppSyncRealTimeClientFactory.appSyncRealTimeEndpoint(appSyncEndpoint),
2632
URL(string: "wss://abc.appsync-realtime-api.amazonaws.com/graphql")
2733
)
34+
35+
let appSyncEndpointCN = URL(string: "wss://abc.appsync-realtime-api.amazonaws.com.cn/graphql")!
36+
XCTAssertEqual(
37+
AppSyncRealTimeClientFactory.appSyncRealTimeEndpoint(appSyncEndpointCN),
38+
URL(string: "wss://abc.appsync-realtime-api.amazonaws.com.cn/graphql")
39+
)
2840
}
2941

3042
func testAppSyncRealTimeEndpoint_withCustomDomain_returnCorrectRealtimePath() {
@@ -33,6 +45,12 @@ class AppSyncRealTimeClientFactoryTests: XCTestCase {
3345
AppSyncRealTimeClientFactory.appSyncRealTimeEndpoint(appSyncEndpoint),
3446
URL(string: "https://test.example.com/graphql/realtime")
3547
)
48+
49+
let appSyncEndpointCN = URL(string: "https://test.example.com.cn/graphql")!
50+
XCTAssertEqual(
51+
AppSyncRealTimeClientFactory.appSyncRealTimeEndpoint(appSyncEndpointCN),
52+
URL(string: "https://test.example.com.cn/graphql/realtime")
53+
)
3654
}
3755

3856
func testAppSyncApiEndpoint_withAWSAppSyncRealTimeDomain_returnCorrectApiDomain() {
@@ -41,6 +59,12 @@ class AppSyncRealTimeClientFactoryTests: XCTestCase {
4159
AppSyncRealTimeClientFactory.appSyncApiEndpoint(appSyncEndpoint),
4260
URL(string: "https://abc.appsync-api.amazonaws.com/graphql")
4361
)
62+
63+
let appSyncEndpointCN = URL(string: "wss://abc.appsync-realtime-api.amazonaws.com.cn/graphql")!
64+
XCTAssertEqual(
65+
AppSyncRealTimeClientFactory.appSyncApiEndpoint(appSyncEndpointCN),
66+
URL(string: "https://abc.appsync-api.amazonaws.com.cn/graphql")
67+
)
4468
}
4569

4670
func testAppSyncApiEndpoint_withAWSAppSyncApiDomain_returnTheSameDomain() {
@@ -49,6 +73,12 @@ class AppSyncRealTimeClientFactoryTests: XCTestCase {
4973
AppSyncRealTimeClientFactory.appSyncApiEndpoint(appSyncEndpoint),
5074
URL(string: "https://abc.appsync-api.amazonaws.com/graphql")
5175
)
76+
77+
let appSyncEndpointCN = URL(string: "https://abc.appsync-api.amazonaws.com.cn/graphql")!
78+
XCTAssertEqual(
79+
AppSyncRealTimeClientFactory.appSyncApiEndpoint(appSyncEndpointCN),
80+
URL(string: "https://abc.appsync-api.amazonaws.com.cn/graphql")
81+
)
5282
}
5383

5484
func testAppSyncApiEndpoint_withCustomDomain_returnCorrectRealtimePath() {
@@ -57,5 +87,11 @@ class AppSyncRealTimeClientFactoryTests: XCTestCase {
5787
AppSyncRealTimeClientFactory.appSyncApiEndpoint(appSyncEndpoint),
5888
URL(string: "https://test.example.com/graphql")
5989
)
90+
91+
let appSyncEndpointCN = URL(string: "https://test.example.com.cn/graphql")!
92+
XCTAssertEqual(
93+
AppSyncRealTimeClientFactory.appSyncApiEndpoint(appSyncEndpointCN),
94+
URL(string: "https://test.example.com.cn/graphql")
95+
)
6096
}
6197
}

0 commit comments

Comments
 (0)