Skip to content

Commit c046b27

Browse files
authored
Refactor websocket implementation directly into ApolloWebSocket (#1906)
* WIP: Moving Starscream Websocket into ApolloWebSocket * Modernize unsafe data access in compression * Minor cleanup of headers * Clean up use of constants * Break Stream into new file * Cleanup more unsafe code warnings * Cleanup * Fix scoping of WSError * Remove Starscream dependency * Fix websocket protocol configuration * Clean up integration tests * Doc changes from code review requests * Move Starscream files into subfolder * Rename ApolloWebSocket default implementation subfolder
1 parent 93b7d57 commit c046b27

19 files changed

Lines changed: 1943 additions & 153 deletions

Apollo.podspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ Pod::Spec.new do |s|
4040
s.subspec 'WebSocket' do |ss|
4141
ss.source_files = 'Sources/ApolloWebSocket/*.swift'
4242
ss.dependency 'Apollo/Core'
43-
ss.dependency 'Apollo-Starscream', '~>3.1.2'
4443
end
4544

4645
end

Apollo.xcodeproj/project.pbxproj

Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,12 @@
190190
DE0586362669957800265760 /* CacheReference.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE664ED92666DF150054DB4F /* CacheReference.swift */; };
191191
DE0586372669958F00265760 /* GraphQLError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FC9A9D21E2FD48B0023C4D5 /* GraphQLError.swift */; };
192192
DE0586392669985000265760 /* Dictionary+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE0586382669985000265760 /* Dictionary+Helpers.swift */; };
193-
DE3A2816268BCE6700A1BDC8 /* Starscream in Frameworks */ = {isa = PBXBuildFile; productRef = DE3A2815268BCE6700A1BDC8 /* Starscream */; };
193+
DE181A2C26C5C0CB000C0B9C /* WebSocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE181A2B26C5C0CB000C0B9C /* WebSocket.swift */; };
194+
DE181A2E26C5C299000C0B9C /* SSLClientCertificate.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE181A2D26C5C299000C0B9C /* SSLClientCertificate.swift */; };
195+
DE181A3026C5C38E000C0B9C /* SSLSecurity.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE181A2F26C5C38E000C0B9C /* SSLSecurity.swift */; };
196+
DE181A3226C5C401000C0B9C /* Compression.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE181A3126C5C401000C0B9C /* Compression.swift */; };
197+
DE181A3426C5D8D4000C0B9C /* CompressionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE181A3326C5D8D4000C0B9C /* CompressionTests.swift */; };
198+
DE181A3626C5DE4F000C0B9C /* WebSocketStream.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE181A3526C5DE4F000C0B9C /* WebSocketStream.swift */; };
194199
DE3C7974260A646300D2F4FF /* dist in Resources */ = {isa = PBXBuildFile; fileRef = DE3C7973260A646300D2F4FF /* dist */; };
195200
DE56DC232683B2020090D6E4 /* DefaultInterceptorProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE56DC222683B2020090D6E4 /* DefaultInterceptorProvider.swift */; };
196201
DE674D9D261CEEE4000E8FC8 /* c.txt in Resources */ = {isa = PBXBuildFile; fileRef = 9B2061172591B3550020D1E0 /* c.txt */; };
@@ -199,7 +204,6 @@
199204
DE6B156A261505660068D642 /* GraphQLMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE6B154A261505450068D642 /* GraphQLMap.swift */; };
200205
DE6B15AF26152BE10068D642 /* DefaultInterceptorProviderIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE6B15AE26152BE10068D642 /* DefaultInterceptorProviderIntegrationTests.swift */; };
201206
DE6B15B126152BE10068D642 /* Apollo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9FC750441D2A532C00458D91 /* Apollo.framework */; };
202-
DE8C84F5268BC42100C54D02 /* DefaultWebSocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE8C84F4268BC42100C54D02 /* DefaultWebSocket.swift */; };
203207
DECD46D0262F64D000924527 /* StarWarsApolloSchemaDownloaderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DECD46CF262F64D000924527 /* StarWarsApolloSchemaDownloaderTests.swift */; };
204208
DECD46FB262F659500924527 /* ApolloCodegenLib.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9B7B6F47233C26D100F32205 /* ApolloCodegenLib.framework */; };
205209
DECD4736262F668500924527 /* UploadAPI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9B2DFBB624E1FA0D00ED3AE6 /* UploadAPI.framework */; };
@@ -742,6 +746,12 @@
742746
DE05862426697A8C00265760 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
743747
DE0586322669948500265760 /* InputValue+Evaluation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "InputValue+Evaluation.swift"; sourceTree = "<group>"; };
744748
DE0586382669985000265760 /* Dictionary+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Dictionary+Helpers.swift"; sourceTree = "<group>"; };
749+
DE181A2B26C5C0CB000C0B9C /* WebSocket.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebSocket.swift; sourceTree = "<group>"; };
750+
DE181A2D26C5C299000C0B9C /* SSLClientCertificate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SSLClientCertificate.swift; sourceTree = "<group>"; };
751+
DE181A2F26C5C38E000C0B9C /* SSLSecurity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SSLSecurity.swift; sourceTree = "<group>"; };
752+
DE181A3126C5C401000C0B9C /* Compression.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Compression.swift; sourceTree = "<group>"; };
753+
DE181A3326C5D8D4000C0B9C /* CompressionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompressionTests.swift; sourceTree = "<group>"; };
754+
DE181A3526C5DE4F000C0B9C /* WebSocketStream.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebSocketStream.swift; sourceTree = "<group>"; };
745755
DE3C7973260A646300D2F4FF /* dist */ = {isa = PBXFileReference; lastKnownFileType = folder; path = dist; sourceTree = "<group>"; };
746756
DE3C7B10260A6FC900D2F4FF /* SelectionSet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SelectionSet.swift; sourceTree = "<group>"; };
747757
DE3C7B11260A6FC900D2F4FF /* ResponseDict.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ResponseDict.swift; sourceTree = "<group>"; };
@@ -777,7 +787,6 @@
777787
DE6B160B26152D210068D642 /* Project-Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Project-Debug.xcconfig"; sourceTree = "<group>"; };
778788
DE6B160C26152D210068D642 /* Workspace-Packaging.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Workspace-Packaging.xcconfig"; sourceTree = "<group>"; };
779789
DE6B160D26152D210068D642 /* Workspace-Shared.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Workspace-Shared.xcconfig"; sourceTree = "<group>"; };
780-
DE8C84F4268BC42100C54D02 /* DefaultWebSocket.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultWebSocket.swift; sourceTree = "<group>"; };
781790
DECD46CF262F64D000924527 /* StarWarsApolloSchemaDownloaderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StarWarsApolloSchemaDownloaderTests.swift; sourceTree = "<group>"; };
782791
DECD490B262F81BF00924527 /* ApolloCodegenTestSupport.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ApolloCodegenTestSupport.framework; sourceTree = BUILT_PRODUCTS_DIR; };
783792
DECD490D262F81BF00924527 /* ApolloCodegenTestSupport.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ApolloCodegenTestSupport.h; sourceTree = "<group>"; };
@@ -829,7 +838,6 @@
829838
buildActionMask = 2147483647;
830839
files = (
831840
9B7BDAFD23FDEE9300ACD198 /* Apollo.framework in Frameworks */,
832-
DE3A2816268BCE6700A1BDC8 /* Starscream in Frameworks */,
833841
);
834842
runOnlyForDeploymentPostprocessing = 0;
835843
};
@@ -1165,8 +1173,8 @@
11651173
9B7BDA9323FDE94C00ACD198 /* ApolloWebSocket */ = {
11661174
isa = PBXGroup;
11671175
children = (
1176+
E676C11F26CB05F90091215A /* DefaultImplementation */,
11681177
9B7BDA9823FDE94C00ACD198 /* WebSocketClient.swift */,
1169-
DE8C84F4268BC42100C54D02 /* DefaultWebSocket.swift */,
11701178
9B7BDA9723FDE94C00ACD198 /* OperationMessage.swift */,
11711179
9B7BDA9623FDE94C00ACD198 /* SplitNetworkTransport.swift */,
11721180
9B7BDA9423FDE94C00ACD198 /* WebSocketError.swift */,
@@ -1715,10 +1723,23 @@
17151723
9B7BDA8923FDE92900ACD198 /* WebSocketTests.swift */,
17161724
9B7BDA8A23FDE92900ACD198 /* SplitNetworkTransportTests.swift */,
17171725
D90F1AF92479DEE5007A1534 /* WebSocketTransportTests.swift */,
1726+
DE181A3326C5D8D4000C0B9C /* CompressionTests.swift */,
17181727
);
17191728
path = WebSocket;
17201729
sourceTree = "<group>";
17211730
};
1731+
E676C11F26CB05F90091215A /* DefaultImplementation */ = {
1732+
isa = PBXGroup;
1733+
children = (
1734+
DE181A3126C5C401000C0B9C /* Compression.swift */,
1735+
DE181A2B26C5C0CB000C0B9C /* WebSocket.swift */,
1736+
DE181A3526C5DE4F000C0B9C /* WebSocketStream.swift */,
1737+
DE181A2D26C5C299000C0B9C /* SSLClientCertificate.swift */,
1738+
DE181A2F26C5C38E000C0B9C /* SSLSecurity.swift */,
1739+
);
1740+
path = DefaultImplementation;
1741+
sourceTree = "<group>";
1742+
};
17221743
/* End PBXGroup section */
17231744

17241745
/* Begin PBXHeadersBuildPhase section */
@@ -1879,12 +1900,10 @@
18791900
buildRules = (
18801901
);
18811902
dependencies = (
1882-
9B7BDAFF23FDEF9E00ACD198 /* PBXTargetDependency */,
18831903
9B7BDAFC23FDEE9000ACD198 /* PBXTargetDependency */,
18841904
);
18851905
name = ApolloWebSocket;
18861906
packageProductDependencies = (
1887-
DE3A2815268BCE6700A1BDC8 /* Starscream */,
18881907
);
18891908
productName = ApolloWebSocket;
18901909
productReference = 9B7BDA7D23FDE90400ACD198 /* ApolloWebSocket.framework */;
@@ -2014,7 +2033,6 @@
20142033
);
20152034
name = Apollo;
20162035
packageProductDependencies = (
2017-
DE8C84F3268BBF8000C54D02 /* Starscream */,
20182036
);
20192037
productName = Apollo;
20202038
productReference = 9FC750441D2A532C00458D91 /* Apollo.framework */;
@@ -2202,7 +2220,6 @@
22022220
mainGroup = 9FC7503A1D2A532C00458D91;
22032221
packageReferences = (
22042222
9B7BDAF423FDEE2600ACD198 /* XCRemoteSwiftPackageReference "SQLite.swift" */,
2205-
DE8C84F2268BBF8000C54D02 /* XCRemoteSwiftPackageReference "Starscream" */,
22062223
);
22072224
productRefGroup = 9FC750451D2A532C00458D91 /* Products */;
22082225
projectDirPath = "";
@@ -2439,12 +2456,16 @@
24392456
buildActionMask = 2147483647;
24402457
files = (
24412458
9B7BDA9F23FDE94C00ACD198 /* WebSocketClient.swift in Sources */,
2459+
DE181A2C26C5C0CB000C0B9C /* WebSocket.swift in Sources */,
2460+
DE181A2E26C5C299000C0B9C /* SSLClientCertificate.swift in Sources */,
24422461
9B7BDAA023FDE94C00ACD198 /* WebSocketTransport.swift in Sources */,
24432462
9B7BDA9C23FDE94C00ACD198 /* WebSocketTask.swift in Sources */,
2444-
DE8C84F5268BC42100C54D02 /* DefaultWebSocket.swift in Sources */,
2463+
DE181A3026C5C38E000C0B9C /* SSLSecurity.swift in Sources */,
24452464
9B7BDA9B23FDE94C00ACD198 /* WebSocketError.swift in Sources */,
24462465
9B7BDA9D23FDE94C00ACD198 /* SplitNetworkTransport.swift in Sources */,
24472466
9B7BDA9E23FDE94C00ACD198 /* OperationMessage.swift in Sources */,
2467+
DE181A3626C5DE4F000C0B9C /* WebSocketStream.swift in Sources */,
2468+
DE181A3226C5C401000C0B9C /* Compression.swift in Sources */,
24482469
);
24492470
runOnlyForDeploymentPostprocessing = 0;
24502471
};
@@ -2629,6 +2650,7 @@
26292650
9FF90A731DDDEB420034C3B6 /* ParseQueryResponseTests.swift in Sources */,
26302651
DED45DE9261B96B70086EF63 /* LoadQueryFromStoreTests.swift in Sources */,
26312652
9BF6C94325194DE2000D5B93 /* MultipartFormData+Testing.swift in Sources */,
2653+
DE181A3426C5D8D4000C0B9C /* CompressionTests.swift in Sources */,
26322654
9F21735B2568F3E200566121 /* PossiblyDeferredTests.swift in Sources */,
26332655
);
26342656
runOnlyForDeploymentPostprocessing = 0;
@@ -2711,10 +2733,6 @@
27112733
target = 9FC750431D2A532C00458D91 /* Apollo */;
27122734
targetProxy = 9B7BDAFB23FDEE9000ACD198 /* PBXContainerItemProxy */;
27132735
};
2714-
9B7BDAFF23FDEF9E00ACD198 /* PBXTargetDependency */ = {
2715-
isa = PBXTargetDependency;
2716-
productRef = 9B7BDAFE23FDEF9E00ACD198 /* Starscream */;
2717-
};
27182736
9B7BDB1723FDF10300ACD198 /* PBXTargetDependency */ = {
27192737
isa = PBXTargetDependency;
27202738
productRef = 9B7BDB1623FDF10300ACD198 /* SQLite */;
@@ -3358,14 +3376,6 @@
33583376
/* End XCConfigurationList section */
33593377

33603378
/* Begin XCRemoteSwiftPackageReference section */
3361-
9B7BDAAA23FDEA7B00ACD198 /* XCRemoteSwiftPackageReference "Starscream" */ = {
3362-
isa = XCRemoteSwiftPackageReference;
3363-
repositoryURL = "https://github.com/daltoniam/Starscream.git";
3364-
requirement = {
3365-
kind = upToNextMinorVersion;
3366-
minimumVersion = 3.1.1;
3367-
};
3368-
};
33693379
9B7BDAF423FDEE2600ACD198 /* XCRemoteSwiftPackageReference "SQLite.swift" */ = {
33703380
isa = XCRemoteSwiftPackageReference;
33713381
repositoryURL = "https://github.com/stephencelis/SQLite.swift.git";
@@ -3374,14 +3384,6 @@
33743384
minimumVersion = 0.12.2;
33753385
};
33763386
};
3377-
DE8C84F2268BBF8000C54D02 /* XCRemoteSwiftPackageReference "Starscream" */ = {
3378-
isa = XCRemoteSwiftPackageReference;
3379-
repositoryURL = "https://github.com/apollographql/Starscream.git";
3380-
requirement = {
3381-
kind = upToNextMinorVersion;
3382-
minimumVersion = 3.1.2;
3383-
};
3384-
};
33853387
/* End XCRemoteSwiftPackageReference section */
33863388

33873389
/* Begin XCSwiftPackageProductDependency section */
@@ -3390,26 +3392,11 @@
33903392
package = 9B7BDAF423FDEE2600ACD198 /* XCRemoteSwiftPackageReference "SQLite.swift" */;
33913393
productName = SQLite;
33923394
};
3393-
9B7BDAFE23FDEF9E00ACD198 /* Starscream */ = {
3394-
isa = XCSwiftPackageProductDependency;
3395-
package = 9B7BDAAA23FDEA7B00ACD198 /* XCRemoteSwiftPackageReference "Starscream" */;
3396-
productName = Starscream;
3397-
};
33983395
9B7BDB1623FDF10300ACD198 /* SQLite */ = {
33993396
isa = XCSwiftPackageProductDependency;
34003397
package = 9B7BDAF423FDEE2600ACD198 /* XCRemoteSwiftPackageReference "SQLite.swift" */;
34013398
productName = SQLite;
34023399
};
3403-
DE3A2815268BCE6700A1BDC8 /* Starscream */ = {
3404-
isa = XCSwiftPackageProductDependency;
3405-
package = DE8C84F2268BBF8000C54D02 /* XCRemoteSwiftPackageReference "Starscream" */;
3406-
productName = Starscream;
3407-
};
3408-
DE8C84F3268BBF8000C54D02 /* Starscream */ = {
3409-
isa = XCSwiftPackageProductDependency;
3410-
package = DE8C84F2268BBF8000C54D02 /* XCRemoteSwiftPackageReference "Starscream" */;
3411-
productName = Starscream;
3412-
};
34133400
DED45E95261B9EE30086EF63 /* SQLite */ = {
34143401
isa = XCSwiftPackageProductDependency;
34153402
package = 9B7BDAF423FDEE2600ACD198 /* XCRemoteSwiftPackageReference "SQLite.swift" */;

Apollo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ let package = Package(
3838
dependencies: [
3939
.package(
4040
url: "https://github.com/stephencelis/SQLite.swift.git",
41-
.upToNextMinor(from: "0.12.2")),
42-
.package(
43-
url: "https://github.com/apollographql/Starscream",
44-
.upToNextMinor(from: "3.1.2")),
41+
.upToNextMinor(from: "0.12.2"))
4542
],
4643
targets: [
4744
.target(
@@ -92,8 +89,7 @@ let package = Package(
9289
name: "ApolloWebSocket",
9390
dependencies: [
9491
"Apollo",
95-
"ApolloUtils",
96-
.product(name: "Starscream", package: "Starscream"),
92+
"ApolloUtils"
9793
],
9894
exclude: [
9995
"Info.plist"

0 commit comments

Comments
 (0)