Skip to content

Commit aeef8e1

Browse files
Merge pull request #10 from GraphQLSwift/chore/update-websocket-protocols
chore: Update WebSocket subprotocols
2 parents 7fa1bb6 + 72752db commit aeef8e1

5 files changed

Lines changed: 26 additions & 20 deletions

File tree

Examples/HelloWorld/Package.resolved

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

Package.resolved

Lines changed: 7 additions & 7 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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ let package = Package(
1515
],
1616
dependencies: [
1717
.package(url: "https://github.com/GraphQLSwift/GraphQL.git", from: "4.0.0"),
18-
.package(url: "https://github.com/GraphQLSwift/GraphQLTransportWS.git", from: "1.0.0"),
19-
.package(url: "https://github.com/GraphQLSwift/GraphQLWS.git", from: "1.0.0"),
18+
.package(url: "https://github.com/GraphQLSwift/GraphQLTransportWS.git", from: "2.0.0"),
19+
.package(url: "https://github.com/GraphQLSwift/GraphQLWS.git", from: "2.0.0"),
2020
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"),
2121
],
2222
targets: [

Sources/GraphQLVapor/WebSocket/GraphQLHandler+handleWebSocket.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@ extension GraphQLHandler {
2222
}
2323
},
2424
onUpgrade: { websocket in
25-
let messageStream = AsyncThrowingStream<String, Error> { continuation in
25+
let messageStream = AsyncThrowingStream<Data, Error> { continuation in
26+
// By subprotocol specs, messages must be `text` and UTF8
2627
websocket.onText { _, text in
27-
continuation.yield(text)
28+
guard let data = text.data(using: .utf8) else {
29+
return
30+
}
31+
continuation.yield(data)
2832
}
2933
websocket.onClose.whenComplete { result in
3034
switch result {

Sources/GraphQLVapor/WebSocket/WebSocketMessenger.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import GraphQLTransportWS
22
import GraphQLWS
33
import WebSocketKit
44

5+
import struct Foundation.Data
6+
57
/// Messenger wrapper for WebSockets
68
struct WebSocketMessenger: GraphQLTransportWS.Messenger, GraphQLWS.Messenger {
79
let websocket: WebSocket
810

9-
func send<S: Collection>(_ message: S) async throws where S.Element == Character {
10-
try await websocket.send(message)
11+
func send(_ message: Data) async throws {
12+
try await websocket.send(String(decoding: message, as: UTF8.self))
1113
}
1214

1315
func error(_ message: String, code: Int) async throws {

0 commit comments

Comments
 (0)