Skip to content
This repository was archived by the owner on Jan 16, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
a8a35ae
Attempted fix for integration test failing on CI (#2024)
AnthonyMDev Nov 9, 2021
ece5b5b
fix(deps): update dependency gatsby-theme-apollo-docs to v5.3.6 (#2026)
renovate[bot] Nov 10, 2021
55c5db8
Update apollo-tooling to v2.33.9 (#2028)
calvincestari Nov 12, 2021
8d48031
Gateway clarification based on license change
hwillson Nov 12, 2021
46957a3
Update SQLite.swift to version 13.0 (#2015)
Iron-Ham Nov 17, 2021
d93568f
Release `0.50.0` (#2031)
calvincestari Nov 17, 2021
3262cd0
fix(deps): update dependency gatsby-theme-apollo-docs to v5.3.8 (#2038)
renovate[bot] Nov 18, 2021
f1707b4
Update caching.mdx (#2042)
bogdanbeczkowski Nov 24, 2021
c3687d2
Update ROADMAP.md (#2053)
calvincestari Dec 7, 2021
f192578
Clean up Github API for performance tests
AnthonyMDev Dec 13, 2021
c3969d1
fix(deps): update dependency gatsby-theme-apollo-docs to v5.3.9 (#2062)
renovate[bot] Dec 13, 2021
dbd7b87
Make filesystem diagram a bit easier to understand (#2063)
designatednerd Dec 14, 2021
67d86ae
Allow periods in arguments to be ignored when parsing cacheKeys (#2057)
Iron-Ham Dec 15, 2021
5079b14
fix(deps): update dependency gatsby-theme-apollo-docs to v5.3.11 (#2068)
renovate[bot] Dec 16, 2021
4d8b5bb
fix(deps): update dependency gatsby-theme-apollo-docs to v5.3.12 (#2074)
renovate[bot] Dec 17, 2021
95ee510
Add tutorial on subscriptions to match Android (#2072)
designatednerd Dec 20, 2021
0358975
Bump mermaid from 8.13.6 to 8.13.8 in /docs (#2083)
dependabot[bot] Jan 6, 2022
d46bd37
chore(deps): update dependency engine.io to 4.1.2 [security] (#2094)
renovate[bot] Jan 13, 2022
60ecd70
chore(deps): update dependency follow-redirects to 1.14.7 [security] …
renovate[bot] Jan 13, 2022
d44820d
chore(deps): update dependency node-forge to 1.0.0 [security] (#2095)
renovate[bot] Jan 13, 2022
fbeee46
Add note about acceptable extensions for types of schema file. (#2059)
designatednerd Jan 19, 2022
a4e7b4f
Docs: Bump to Gatsby v3 (#2104)
jgarrow Jan 25, 2022
0c9aa54
fix(deps): pin dependency gatsby-theme-apollo-docs to 6.0.0 (#2113)
renovate[bot] Jan 26, 2022
161873b
fix(deps): pin dependency gatsby to 3.14.6 (#2123)
renovate[bot] Jan 29, 2022
63eacd1
Edits to intro and installation docs (#2125)
Feb 1, 2022
eb6cbe1
Fix tutorial URL and tweak downloading a schema article (#2133)
Feb 3, 2022
7538bef
Split advanced "Creating a client" content into separate article (#2143)
Feb 7, 2022
ca88016
Disable flaky integration test
AnthonyMDev Feb 8, 2022
f51e7c4
Update gatsby config to deploy 1.0 alpha docs
AnthonyMDev Feb 8, 2022
ec034e8
Update roadmap after 1.0.0-alpha.1 release (#2145)
calvincestari Feb 9, 2022
0beea3d
[v1.0.0 Alpha 1] JavascriptError @unchecked Sendable (#2147)
TizianoCoroneo Feb 11, 2022
bf4cb5a
Update documentation to clarify schema download format and filename (…
calvincestari Feb 14, 2022
3c58987
chore(deps): update dependency follow-redirects to 1.14.8 [security] …
renovate[bot] Feb 14, 2022
f409e81
Update license copyright notice
calvincestari Feb 15, 2022
cf713c1
Delete Jazzy config - not supported
calvincestari Feb 16, 2022
c188637
Update list of active maintainers
calvincestari Feb 16, 2022
2b607ec
[Fix #2170] Do not refetch query watcher from server after cache miss…
AnthonyMDev Feb 25, 2022
bf86e01
Add `graphql-ws` protocol support (#2168)
calvincestari Feb 25, 2022
8b6a50a
chore(deps): update dependency prismjs to 1.27.0 [security] (#2179)
renovate[bot] Feb 28, 2022
cb5f1ce
Release 0.51.0 (#2086)
calvincestari Feb 28, 2022
664c1f1
Enable lazy access to the request body creation for leverage in custo…
rickfast Mar 3, 2022
52bbeac
Release `0.51.1` (#2188)
calvincestari Mar 7, 2022
6aee64a
Updates for new docs infra (#2197)
trevorblades Mar 15, 2022
f916c5f
Remove files from old Gatsby docs theme (#2202)
jgarrow Mar 15, 2022
62f4554
Clear body on APQ retry in JSONRequest (#2206)
AnthonyMDev Mar 18, 2022
729fedb
Release 0.51.2 (#2207)
AnthonyMDev Mar 18, 2022
08a41ba
Fix changelog version.
AnthonyMDev Mar 18, 2022
fecf44b
Add netlify config for deploy previews (#2208)
trevorblades Mar 22, 2022
b25d1de
Add codegen option for excludes (#2205)
bannzai Mar 23, 2022
a5f6f5d
Fix typo (#2212)
changm4n Mar 23, 2022
b4f58e2
Start a docs production deploy when docs changes get merged (#2211)
trevorblades Mar 23, 2022
4772297
Bump minimist from 1.2.5 to 1.2.6 in /SimpleUploadServer (#2214)
dependabot[bot] Mar 23, 2022
79876e5
Bump node-fetch from 2.6.6 to 2.6.7 in /SimpleUploadServer (#2215)
dependabot[bot] Mar 23, 2022
a563c40
Add note to tutorial about the `graphql-ws` subscription library (#2219)
rkoron007 Mar 25, 2022
c8c3951
Update tutorial-obtain-schema.md (#2225)
Carrione Mar 29, 2022
26351b5
Update tutorial-execute-query.md (#2228)
Carrione Mar 29, 2022
ab160e4
chore: Update Xcode build tool versions on CircleCI (#2242)
calvincestari Apr 8, 2022
57f329d
chore: Update roadmap
calvincestari Apr 15, 2022
b9a6116
fix: Sandbox documentation links (#2254)
martinbonnin Apr 21, 2022
09003c7
ci: Update xcode image to fix Node version mismatch
calvincestari Apr 21, 2022
fc260c7
ci: Update Node version to match what is installed with Xcode 13.3.1 …
calvincestari Apr 21, 2022
90d2c34
chore: updates roadmap (#2258)
jpvajda Apr 27, 2022
51c686f
Update build phases example to propagate errors to Xcode (#2260)
adam-zethraeus May 3, 2022
eecef09
Add a comment about a new use of the X-APOLLO-OPERATION-NAME header (…
glasser May 5, 2022
c78e0b1
Set permissions for GitHub actions (#2248)
neilnaveen May 16, 2022
858c769
updates roadmap for june 2022 (#2295)
jpvajda Jun 6, 2022
51c81bd
Update CircleCI tool versions (#2304)
calvincestari Jun 8, 2022
402dd16
fix: `graphql_transport_ws` protocol should send 'complete' to end su…
calvincestari Jun 17, 2022
c0a8ce3
Replace print statement with CodegenLogger.log (#2348)
hiltonc Jun 29, 2022
d26751a
Fix buttons on docs root (#2369)
Jul 12, 2022
f214c8e
Expose GraphQLResultError Path String (#2361)
Jul 12, 2022
414cc63
Revert "Fix buttons on docs root (#2369)" (#2371)
trevorblades Jul 12, 2022
0c43e49
release: 0.52.0 (#2370)
calvincestari Jul 14, 2022
bfa089b
Fix typo (#2379)
mischa-hildebrand Jul 18, 2022
b2ed705
Fix incorrect parameter name (#2380)
mischa-hildebrand Jul 18, 2022
135acc4
chore: Update ROADMAP for Beta release cycle (#2393)
calvincestari Jul 25, 2022
928f9ea
Remove all instances of bitcode as not supported in Xcode 14 (#2398)
stareque-atlassian Jul 28, 2022
42646f7
Release 0.53.0 (#2406)
calvincestari Jul 29, 2022
5f31e2a
fix: checkout at tag with legacy optionals behavior (#2412)
calvincestari Aug 2, 2022
323ed07
Update version in Swift Scripting docs (#2416)
redryerye Aug 3, 2022
ddc8953
Re-added support for iOS 11
adamayoung Aug 18, 2022
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
Prev Previous commit
Next Next commit
Add graphql-ws protocol support (apollographql#2168)
* Implement graphql-transport-ws protocol support
* Add graphql-transport-ws integration test based on Apollo Server docs-examples
* Add CI step for Apollo Server graphql-transport-ws tests
* After installing node v12 switch to use v16
* Instruct nvm to use version in .nvmrc
* Update documentation and tutorial
* Change WSProtocol cases to closer match library names
* Remove initializer defaults and require web socket protocol on designated initializer.
* Update Subscriptions documentation
* Add WSProtocol option for AWS AppSync
* Add ping/pong message support required by graphql-ws
* Update documentation and tutorial
* Add tests for subscriptionWsProtocol
* Add tests for graphqlWSProtocol
* Revert to naming aligned with the protocols and not the implementation libraries
* Use longer async timeout for slower environments like CI
* Fix test names
* Fix project configuration
* Rename protocol parameter on WebSocket initializers
* Revert "Use longer async timeout for slower environments like CI"
* Fix async timing bug and refactor websocket protocol tests
  • Loading branch information
calvincestari authored Feb 25, 2022
commit bf86e01a1a3c2c78d1817cc01e1875caf8261b89
17 changes: 15 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ commands:
steps:
- restore_cache:
key: starwars-server
- restore_cache:
key: apollo-server-graphql-transport-ws
- common_test_setup
- run:
command: ./scripts/install-node.sh
command: ./scripts/install-node-v12.sh
name: Install Node
- run:
command: ./scripts/install-or-update-starwars-server.sh
Expand All @@ -43,18 +45,29 @@ commands:
name: Start StarWars Server
background: true
- run:
command: cd SimpleUploadServer && npm install && npm start
command: cd SimpleUploadServer && nvm use && npm install && npm start
name: Start Upload Server
background: true
- run:
command: sudo chmod -R +rwx SimpleUploadServer
name: Adjust permissions for simple upload server folder
- run:
command: ./scripts/install-apollo-server-docs-example-server.sh
name: Install Apollo Server (graphql-transport-ws configuration)
- run:
command: cd ../docs-examples/apollo-server/v3/subscriptions-graphql-ws && npm start
name: Start Apollo Server (graphql-transport-ws configuration)
background: true
integration_test_cleanup:
steps:
- save_cache:
key: starwars-server
paths:
- ../starwars-server
- save_cache:
key: apollo-server-graphql-transport-ws
paths:
- ../docs-examples/apollo-server/v3/subscriptions-graphql-ws
common_test_setup:
description: Commands to run for setup of every set of tests
steps:
Expand Down
202 changes: 202 additions & 0 deletions Apollo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Configuration/Apollo/Apollo-Target-SubscriptionAPI.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "../Shared/Workspace-Universal-Framework.xcconfig"

INFOPLIST_FILE = Sources/SubscriptionAPI/Info.plist
1 change: 1 addition & 0 deletions SimpleUploadServer/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v12.22.10
4 changes: 3 additions & 1 deletion SimpleUploadServer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ const server = new ApolloServer({
}
});

server.listen().then(({ url }) => {
server.listen({
port: 4001
}).then(({ url }) => {
console.info(`Upload server started at ${url}`);
});
18 changes: 18 additions & 0 deletions Sources/ApolloTestSupport/MockWebSocketDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Foundation
@testable import ApolloWebSocket

public class MockWebSocketDelegate: WebSocketClientDelegate {
public var didReceiveMessage: ((String) -> Void)?

public init() {}

public func websocketDidConnect(socket: WebSocketClient) {}

public func websocketDidDisconnect(socket: WebSocketClient, error: Error?) {}

public func websocketDidReceiveMessage(socket: WebSocketClient, text: String) {
didReceiveMessage?(text)
}

public func websocketDidReceiveData(socket: WebSocketClient, data: Data) {}
}
58 changes: 47 additions & 11 deletions Sources/ApolloWebSocket/DefaultImplementation/WebSocket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,30 @@ public final class WebSocket: NSObject, WebSocketClient, StreamDelegate, WebSock
public let code: Int
}

private struct Constants {
/// The GraphQL over WebSocket protocols supported by apollo-ios.
public enum WSProtocol: CustomStringConvertible {
/// WebSocket protocol `graphql-ws`. This is implemented by the [subscriptions-transport-ws](https://github.com/apollographql/subscriptions-transport-ws)
/// and AWS AppSync libraries.
case graphql_ws
/// WebSocket protocol `graphql-transport-ws`. This is implemented by the [graphql-ws](https://github.com/enisdenjo/graphql-ws)
/// library.
case graphql_transport_ws

public var description: String {
switch self {
case .graphql_ws: return "graphql-ws"
case .graphql_transport_ws: return "graphql-transport-ws"
}
}
}

struct Constants {
static let headerWSUpgradeName = "Upgrade"
static let headerWSUpgradeValue = "websocket"
static let headerWSHostName = "Host"
static let headerWSConnectionName = "Connection"
static let headerWSConnectionValue = "Upgrade"
static let headerWSProtocolName = "Sec-WebSocket-Protocol"
static let headerWSProtocolValue = "graphql-ws"
static let headerWSVersionName = "Sec-WebSocket-Version"
static let headerWSVersionValue = "13"
static let headerWSExtensionName = "Sec-WebSocket-Extensions"
Expand Down Expand Up @@ -183,8 +199,12 @@ public final class WebSocket: NSObject, WebSocketClient, StreamDelegate, WebSock
return canWork
}

/// Used for setting protocols.
public init(request: URLRequest) {
/// Designated initializer.
///
/// - Parameters:
/// - request: A URL request object that provides request-specific information such as the URL.
/// - protocol: Protocol to use for communication over the web socket.
public init(request: URLRequest, protocol: WSProtocol) {
self.request = request
self.stream = FoundationStream()
if request.value(forHTTPHeaderField: Constants.headerOriginName) == nil {
Expand All @@ -197,20 +217,36 @@ public final class WebSocket: NSObject, WebSocketClient, StreamDelegate, WebSock
self.request.setValue(origin, forHTTPHeaderField: Constants.headerOriginName)
}

self.request.setValue(Constants.headerWSProtocolValue,
forHTTPHeaderField: Constants.headerWSProtocolName)
self.request.setValue(`protocol`.description, forHTTPHeaderField: Constants.headerWSProtocolName)

writeQueue.maxConcurrentOperationCount = 1
}

public convenience init(url: URL) {
/// Convenience initializer to specify the URL and web socket protocol.
///
/// - Parameters:
/// - url: The destination URL to connect to.
/// - protocol: Protocol to use for communication over the web socket.
public convenience init(url: URL, protocol: WSProtocol) {
var request = URLRequest(url: url)
request.timeoutInterval = 5
self.init(request: request)

self.init(request: request, protocol: `protocol`)
}

// Used for specifically setting the QOS for the write queue.
public convenience init(url: URL, writeQueueQOS: QualityOfService) {
self.init(url: url)
/// Convenience initializer to specify the URL and web socket protocol with a specific quality of
/// service on the write queue.
///
/// - Parameters:
/// - url: The destination URL to connect to.
/// - writeQueueQOS: Specifies the quality of service for the write queue.
/// - protocol: Protocol to use for communication over the web socket.
public convenience init(
url: URL,
writeQueueQOS: QualityOfService,
protocol: WSProtocol
) {
self.init(url: url, protocol: `protocol`)
writeQueue.qualityOfService = writeQueueQOS
}

Expand Down
13 changes: 12 additions & 1 deletion Sources/ApolloWebSocket/OperationMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ final class OperationMessage {
enum Types : String {
case connectionInit = "connection_init" // Client -> Server
case connectionTerminate = "connection_terminate" // Client -> Server
case subscribe = "subscribe" // Client -> Server
case start = "start" // Client -> Server
case stop = "stop" // Client -> Server

Expand All @@ -17,6 +18,10 @@ final class OperationMessage {
case data = "data" // Server -> Client
case error = "error" // Server -> Client
case complete = "complete" // Server -> Client
case next = "next" // Server -> Client

case ping = "ping" // Bidirectional
case pong = "pong" // Bidirectional
}

let serializationFormat = JSONSerializationFormat.self
Expand All @@ -34,7 +39,7 @@ final class OperationMessage {

init(payload: GraphQLMap? = nil,
id: String? = nil,
type: Types = .start) {
type: Types) {
var message: GraphQLMap = [:]
if let payload = payload {
message["payload"] = payload
Expand Down Expand Up @@ -99,6 +104,12 @@ final class OperationMessage {
}
}

extension OperationMessage: CustomDebugStringConvertible {
var debugDescription: String {
rawMessage!
}
}

struct ParseHandler {
let type: String?
let id: String?
Expand Down
19 changes: 17 additions & 2 deletions Sources/ApolloWebSocket/WebSocketTransport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public class WebSocketTransport {

switch messageType {
case .data,
.next,
.error:
if let id = parseHandler.id, let responseHandler = subscribers[id] {
if let payload = parseHandler.payload {
Expand Down Expand Up @@ -180,11 +181,19 @@ public class WebSocketTransport {
writeQueue()

case .connectionKeepAlive,
.startAck:
.startAck,
.pong:
writeQueue()

case .ping:
if let str = OperationMessage(type: .pong).rawMessage {
write(str)
writeQueue()
}

case .connectionInit,
.connectionTerminate,
.subscribe,
.start,
.stop,
.connectionError:
Expand Down Expand Up @@ -270,7 +279,13 @@ public class WebSocketTransport {
sendQueryDocument: true,
autoPersistQuery: false)
let identifier = operationMessageIdCreator.requestId()
guard let message = OperationMessage(payload: body, id: identifier).rawMessage else {

var type: OperationMessage.Types = .start
if case WebSocket.WSProtocol.graphql_transport_ws.description = websocket.request.value(forHTTPHeaderField: WebSocket.Constants.headerWSProtocolName) {
type = .subscribe
}

guard let message = OperationMessage(payload: body, id: identifier, type: type).rawMessage else {
return nil
}

Expand Down
51 changes: 51 additions & 0 deletions Sources/SubscriptionAPI/API.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// @generated
// This file was automatically generated and should not be edited.

import Apollo
import Foundation

public final class IncrementingSubscription: GraphQLSubscription {
/// The raw GraphQL definition of this operation.
public let operationDefinition: String =
"""
subscription Incrementing {
numberIncremented
}
"""

public let operationName: String = "Incrementing"

public let operationIdentifier: String? = "fe12b5f0dfc7fefa513cc8aecef043b45daf2d776fd000d3a7703f9798ecf233"

public init() {
}

public struct Data: GraphQLSelectionSet {
public static let possibleTypes: [String] = ["Subscription"]

public static var selections: [GraphQLSelection] {
return [
GraphQLField("numberIncremented", type: .scalar(Int.self)),
]
}

public private(set) var resultMap: ResultMap

public init(unsafeResultMap: ResultMap) {
self.resultMap = unsafeResultMap
}

public init(numberIncremented: Int? = nil) {
self.init(unsafeResultMap: ["__typename": "Subscription", "numberIncremented": numberIncremented])
}

public var numberIncremented: Int? {
get {
return resultMap["numberIncremented"] as? Int
}
set {
resultMap.updateValue(newValue, forKey: "numberIncremented")
}
}
}
}
24 changes: 24 additions & 0 deletions Sources/SubscriptionAPI/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>
11 changes: 11 additions & 0 deletions Sources/SubscriptionAPI/SubscriptionAPI.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#import <Foundation/Foundation.h>

//! Project version number for SubscriptionAPI.
FOUNDATION_EXPORT double SubscriptionAPIVersionNumber;

//! Project version string for SubscriptionAPI.
FOUNDATION_EXPORT const unsigned char SubscriptionAPIVersionString[];

// In this header, you should import all the public headers of your framework using statements like #import <SubscriptionAPI/PublicHeader.h>


6 changes: 6 additions & 0 deletions Sources/SubscriptionAPI/graphql/operation_ids.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"fe12b5f0dfc7fefa513cc8aecef043b45daf2d776fd000d3a7703f9798ecf233": {
"name": "Incrementing",
"source": "subscription Incrementing {\n numberIncremented\n}"
}
}
7 changes: 7 additions & 0 deletions Sources/SubscriptionAPI/graphql/schema.graphqls
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type Query {
currentNumber: Int
}

type Subscription {
numberIncremented: Int
}
4 changes: 4 additions & 0 deletions Sources/SubscriptionAPI/graphql/subscription.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
subscription Incrementing {
numberIncremented
}

Loading