diff --git a/Examples/HelloWorld/Package.resolved b/Examples/HelloWorld/Package.resolved index 9999fca..0e62a5a 100644 --- a/Examples/HelloWorld/Package.resolved +++ b/Examples/HelloWorld/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "24cbfc68b865463dd46c318af906571b41ff169eaa9848fbf6c71f2b064530bb", + "originHash" : "6dc2d6c87a6cdfc632a08a4d4d645d393b986d542fa02cf5f1be19d02cc8733e", "pins" : [ { "identity" : "async-http-client", @@ -33,8 +33,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/GraphQLSwift/Graphiti.git", "state" : { - "revision" : "a23a3d232df202fc158ad2d698926325b470523c", - "version" : "3.0.0" + "revision" : "3ec7bf90d9884324852af9d96d2ce5aa60e02cde", + "version" : "3.1.0" } }, { @@ -51,8 +51,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/GraphQLSwift/GraphQLTransportWS.git", "state" : { - "revision" : "6d62d9f980346f0644a5f4dc1593f2b0f1d07b44", - "version" : "1.0.0" + "revision" : "1fb0dbdec9bc220949370de3024c525c99b754f4", + "version" : "2.0.0" } }, { @@ -60,8 +60,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/GraphQLSwift/GraphQLWS.git", "state" : { - "revision" : "5a3b62e478668199d22f52df7cc7d44b51394cb4", - "version" : "1.0.0" + "revision" : "038a19b365faa9dc6d225a9499e8cfd992c996fa", + "version" : "2.0.0" } }, { diff --git a/Package.resolved b/Package.resolved index c8aa9ab..626d740 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "78b8062b4c6f9e751b88d65f6b57fb80012daef3bfd81d95874b910c9ce8c7d7", + "originHash" : "1eb52908fbc0ae1b534690c740bf8362cebbe2c158c780d85b12afdfb5665fe2", "pins" : [ { "identity" : "async-http-client", @@ -33,8 +33,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/GraphQLSwift/Graphiti.git", "state" : { - "revision" : "a23a3d232df202fc158ad2d698926325b470523c", - "version" : "3.0.0" + "revision" : "3ec7bf90d9884324852af9d96d2ce5aa60e02cde", + "version" : "3.1.0" } }, { @@ -51,8 +51,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/GraphQLSwift/GraphQLTransportWS.git", "state" : { - "revision" : "6d62d9f980346f0644a5f4dc1593f2b0f1d07b44", - "version" : "1.0.0" + "revision" : "1fb0dbdec9bc220949370de3024c525c99b754f4", + "version" : "2.0.0" } }, { @@ -60,8 +60,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/GraphQLSwift/GraphQLWS.git", "state" : { - "revision" : "5a3b62e478668199d22f52df7cc7d44b51394cb4", - "version" : "1.0.0" + "revision" : "038a19b365faa9dc6d225a9499e8cfd992c996fa", + "version" : "2.0.0" } }, { diff --git a/Package.swift b/Package.swift index 9bfa0c4..542dae8 100644 --- a/Package.swift +++ b/Package.swift @@ -15,8 +15,8 @@ let package = Package( ], dependencies: [ .package(url: "https://github.com/GraphQLSwift/GraphQL.git", from: "4.0.0"), - .package(url: "https://github.com/GraphQLSwift/GraphQLTransportWS.git", from: "1.0.0"), - .package(url: "https://github.com/GraphQLSwift/GraphQLWS.git", from: "1.0.0"), + .package(url: "https://github.com/GraphQLSwift/GraphQLTransportWS.git", from: "2.0.0"), + .package(url: "https://github.com/GraphQLSwift/GraphQLWS.git", from: "2.0.0"), .package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"), ], targets: [ diff --git a/Sources/GraphQLVapor/WebSocket/GraphQLHandler+handleWebSocket.swift b/Sources/GraphQLVapor/WebSocket/GraphQLHandler+handleWebSocket.swift index f0836cc..81633b3 100644 --- a/Sources/GraphQLVapor/WebSocket/GraphQLHandler+handleWebSocket.swift +++ b/Sources/GraphQLVapor/WebSocket/GraphQLHandler+handleWebSocket.swift @@ -22,9 +22,13 @@ extension GraphQLHandler { } }, onUpgrade: { websocket in - let messageStream = AsyncThrowingStream { continuation in + let messageStream = AsyncThrowingStream { continuation in + // By subprotocol specs, messages must be `text` and UTF8 websocket.onText { _, text in - continuation.yield(text) + guard let data = text.data(using: .utf8) else { + return + } + continuation.yield(data) } websocket.onClose.whenComplete { result in switch result { diff --git a/Sources/GraphQLVapor/WebSocket/WebSocketMessenger.swift b/Sources/GraphQLVapor/WebSocket/WebSocketMessenger.swift index e585aa8..87e45cd 100644 --- a/Sources/GraphQLVapor/WebSocket/WebSocketMessenger.swift +++ b/Sources/GraphQLVapor/WebSocket/WebSocketMessenger.swift @@ -2,12 +2,14 @@ import GraphQLTransportWS import GraphQLWS import WebSocketKit +import struct Foundation.Data + /// Messenger wrapper for WebSockets struct WebSocketMessenger: GraphQLTransportWS.Messenger, GraphQLWS.Messenger { let websocket: WebSocket - func send(_ message: S) async throws where S.Element == Character { - try await websocket.send(message) + func send(_ message: Data) async throws { + try await websocket.send(String(decoding: message, as: UTF8.self)) } func error(_ message: String, code: Int) async throws {