Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release - 0.48.0 #1926

Merged
merged 6 commits into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change log

## v0.48.0
- **Customizable subscription message identifiers:** The `WebSocketTransport` initializer can be configured with a subclass of `OperationMessageIdCreator` to provide a unique identifier per request. The default implementation is `ApolloSequencedOperationMessageIdCreator` and retains the current behavior of sequential message numbering. [#1919](https://github.com/apollographql/apollo-ios/pull/1919) - _Thank you to [Clark McNally](https://github.com/cmcnally-beachbody) for the contribution!_
- **AWS AppSync Compatibility:** Apollo-ios will now correctly handle the `start_ack` message that AWS AppSync servers respond with when a subscription is requested. [#1919](https://github.com/apollographql/apollo-ios/pull/1919) - _Thank you to [Clark McNally](https://github.com/cmcnally-beachbody) for the contribution!_
- **Updated to version 2.33.6 of the Apollo CLI:** Applies some new vulnerability patches to the CLI, but should not change any output. [#1929](https://github.com/apollographql/apollo-ios/pull/1929)
- **Improved documentation:** Clarification of cache normalization concepts. [#1710](https://github.com/apollographql/apollo-ios/pull/1710) - _Thank you to [Daniel Morgan](https://github.com/morgz) for the contribution!_

## v0.47.1
- **Fixed - Websocket default implementation not included in `ApolloWebSocket` via Cocoapods:** _Thank you to [ketenshi](https://github.com/ketenshi) for the contribution!_

Expand Down
2 changes: 1 addition & 1 deletion Configuration/Shared/Project-Version.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CURRENT_PROJECT_VERSION = 0.47.1
CURRENT_PROJECT_VERSION = 0.48.0
10 changes: 7 additions & 3 deletions Sources/ApolloWebSocket/OperationMessageIdCreator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ public protocol OperationMessageIdCreator {

// MARK: - Default Implementation

/// The default implementation of `OperationMessageIdCreator` that uses a sequential numbering scheme.
public struct ApolloSequencedOperationMessageIdCreator: OperationMessageIdCreator {
private var sequenceNumberCounter = Atomic<Int>(0)

// Internal init methods cannot be used in public methods

/// Designated initializer.
///
/// - Parameter startAt: The number from which the sequenced numbering scheme should start.
public init(startAt sequenceNumber: Int = 1) {
sequenceNumberCounter = Atomic<Int>(sequenceNumber)
}


/// Returns the number in the current sequence. Will be incremented when calling this method.
public func requestId() -> String {
let id = sequenceNumberCounter.value
_ = sequenceNumberCounter.increment()
Expand Down
3 changes: 2 additions & 1 deletion Sources/ApolloWebSocket/WebSocketTransport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ public class WebSocketTransport {
/// - reconnect: Whether to auto reconnect when websocket looses connection. Defaults to true.
/// - reconnectionInterval: How long to wait before attempting to reconnect. Defaults to half a second.
/// - allowSendingDuplicates: Allow sending duplicate messages. Important when reconnected. Defaults to true.
/// - connectOnInit: Whether the websocket connects immediately on creation. If false, remember to call `resumeWebSocketConnection()` to connect. Defaults to true.
/// - connectOnInit: Whether the websocket connects immediately on creation. If false, remember to call `resumeWebSocketConnection()` to connect. Defaults to true.
/// - connectingPayload: [optional] The payload to send on connection. Defaults to an empty `GraphQLMap`.
/// - requestBodyCreator: The `RequestBodyCreator` to use when serializing requests. Defaults to an `ApolloRequestBodyCreator`.
/// - operationMessageIdCreator: The `OperationMessageIdCreator` used to generate a unique message identifier per request. Defaults to `ApolloSequencedOperationMessageIdCreator`.
public init(websocket: WebSocketClient,
store: ApolloStore? = nil,
clientName: String = WebSocketTransport.defaultClientName,
Expand Down
2 changes: 2 additions & 0 deletions docs/source/api/ApolloWebSocket/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

## Protocols

- [OperationMessageIdCreator](protocols/OperationMessageIdCreator/)
- [SSLTrustValidator](protocols/SSLTrustValidator/)
- [WebSocketClient](protocols/WebSocketClient/)
- [WebSocketClientDelegate](protocols/WebSocketClientDelegate/)
- [WebSocketTransportDelegate](protocols/WebSocketTransportDelegate/)

## Structs

- [ApolloSequencedOperationMessageIdCreator](structs/ApolloSequencedOperationMessageIdCreator/)
- [SSLClientCertificateError](structs/SSLClientCertificateError/)
- [SSLSettings](structs/SSLSettings/)
- [WebSocket.WSError](structs/WebSocket.WSError/)
Expand Down
12 changes: 9 additions & 3 deletions docs/source/api/ApolloWebSocket/classes/WebSocketTransport.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public var clientVersion: String
- NOTE: Setting this won't override immediately if the socket is still connected, only on reconnection.

## Methods
### `init(websocket:store:clientName:clientVersion:sendOperationIdentifiers:reconnect:reconnectionInterval:allowSendingDuplicates:connectOnInit:connectingPayload:requestBodyCreator:)`
### `init(websocket:store:clientName:clientVersion:sendOperationIdentifiers:reconnect:reconnectionInterval:allowSendingDuplicates:connectOnInit:connectingPayload:requestBodyCreator:operationMessageIdCreator:)`

```swift
public init(websocket: WebSocketClient,
Expand All @@ -45,7 +45,8 @@ public init(websocket: WebSocketClient,
allowSendingDuplicates: Bool = true,
connectOnInit: Bool = true,
connectingPayload: GraphQLMap? = [:],
requestBodyCreator: RequestBodyCreator = ApolloRequestBodyCreator())
requestBodyCreator: RequestBodyCreator = ApolloRequestBodyCreator(),
operationMessageIdCreator: OperationMessageIdCreator = ApolloSequencedOperationMessageIdCreator())
```

Designated initializer
Expand All @@ -59,9 +60,10 @@ Designated initializer
- reconnect: Whether to auto reconnect when websocket looses connection. Defaults to true.
- reconnectionInterval: How long to wait before attempting to reconnect. Defaults to half a second.
- allowSendingDuplicates: Allow sending duplicate messages. Important when reconnected. Defaults to true.
- connectOnInit: Whether the websocket connects immediately on creation. If false, remember to call `resumeWebSocketConnection()` to connect. Defaults to true.
- connectOnInit: Whether the websocket connects immediately on creation. If false, remember to call `resumeWebSocketConnection()` to connect. Defaults to true.
- connectingPayload: [optional] The payload to send on connection. Defaults to an empty `GraphQLMap`.
- requestBodyCreator: The `RequestBodyCreator` to use when serializing requests. Defaults to an `ApolloRequestBodyCreator`.
- operationMessageIdCreator: The `OperationMessageIdCreator` used to generate a unique message identifier per request. Defaults to `ApolloSequencedOperationMessageIdCreator`.

#### Parameters

Expand All @@ -75,6 +77,10 @@ Designated initializer
| reconnect | Whether to auto reconnect when websocket looses connection. Defaults to true. |
| reconnectionInterval | How long to wait before attempting to reconnect. Defaults to half a second. |
| allowSendingDuplicates | Allow sending duplicate messages. Important when reconnected. Defaults to true. |
| connectOnInit | Whether the websocket connects immediately on creation. If false, remember to call `resumeWebSocketConnection()` to connect. Defaults to true. |
| connectingPayload | [optional] The payload to send on connection. Defaults to an empty `GraphQLMap`. |
| requestBodyCreator | The `RequestBodyCreator` to use when serializing requests. Defaults to an `ApolloRequestBodyCreator`. |
| operationMessageIdCreator | The `OperationMessageIdCreator` used to generate a unique message identifier per request. Defaults to `ApolloSequencedOperationMessageIdCreator`. |

### `isConnected()`

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
**PROTOCOL**

# `OperationMessageIdCreator`

```swift
public protocol OperationMessageIdCreator
```

## Methods
### `requestId()`

```swift
func requestId() -> String
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
**STRUCT**

# `ApolloSequencedOperationMessageIdCreator`

```swift
public struct ApolloSequencedOperationMessageIdCreator: OperationMessageIdCreator
```

The default implementation of `OperationMessageIdCreator` that uses a sequential numbering scheme.

## Methods
### `init(startAt:)`

```swift
public init(startAt sequenceNumber: Int = 1)
```

Designated initializer.

- Parameter startAt: The number from which the sequenced numbering scheme should start.

#### Parameters

| Name | Description |
| ---- | ----------- |
| startAt | The number from which the sequenced numbering scheme should start. |

### `requestId()`

```swift
public func requestId() -> String
```

Returns the number in the current sequence. Will be incremented when calling this method.