-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates to work with App Sync Subscriptions (#1919)
* Initial changes just to get it working with AppSync * Fix project and package so swift package builds correctly * Add OperationMessageIdCreator to add custom ids * Add tests for OperationMessageIdCreator * Fix up project file * Updates from feedback * Fix unit tests * Updates from feedback to clean up OperationMessageIdCreator and tests * Update to group startAck with connectionKeepAlive Co-authored-by: John Clayton <john@fivesquare.net>
- Loading branch information
1 parent
0bbfda3
commit 550f1b1
Showing
6 changed files
with
123 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Foundation | ||
#if !COCOAPODS | ||
import ApolloUtils | ||
#endif | ||
|
||
public protocol OperationMessageIdCreator { | ||
func requestId() -> String | ||
} | ||
|
||
// MARK: - Default Implementation | ||
|
||
public struct ApolloSequencedOperationMessageIdCreator: OperationMessageIdCreator { | ||
private var sequenceNumberCounter = Atomic<Int>(0) | ||
|
||
// Internal init methods cannot be used in public methods | ||
public init(startAt sequenceNumber: Int = 1) { | ||
sequenceNumberCounter = Atomic<Int>(sequenceNumber) | ||
} | ||
|
||
public func requestId() -> String { | ||
let id = sequenceNumberCounter.value | ||
_ = sequenceNumberCounter.increment() | ||
|
||
return "\(id)" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
Tests/ApolloTests/WebSocket/OperationMessageIdCreatorTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import XCTest | ||
@testable import ApolloWebSocket | ||
import UploadAPI | ||
|
||
class OperationMessageIdCreatorTests: XCTestCase { | ||
struct CustomOperationMessageIdCreator: OperationMessageIdCreator { | ||
func requestId() -> String { | ||
return "12345678" | ||
} | ||
} | ||
|
||
// MARK: - Tests | ||
|
||
func testOperationMessageIdCreatorWithApolloOperationMessageIdCreator() { | ||
let apolloOperationMessageIdCreator = ApolloSequencedOperationMessageIdCreator(startAt: 5) | ||
|
||
let firstId = apolloOperationMessageIdCreator.requestId() | ||
let secondId = apolloOperationMessageIdCreator.requestId() | ||
|
||
XCTAssertEqual(firstId, "5") | ||
XCTAssertEqual(secondId, "6") | ||
} | ||
|
||
func testOperationMessageIdCreatorWithCustomOperationMessageIdCreator() { | ||
let customOperationMessageIdCreator = CustomOperationMessageIdCreator() | ||
|
||
let id = customOperationMessageIdCreator.requestId() | ||
|
||
XCTAssertEqual(id, "12345678") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters