Skip to content
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
14 changes: 7 additions & 7 deletions Examples/HelloWorld/Package.resolved

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

14 changes: 7 additions & 7 deletions Package.resolved

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

4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ extension GraphQLHandler {
}
},
onUpgrade: { websocket in
let messageStream = AsyncThrowingStream<String, Error> { continuation in
let messageStream = AsyncThrowingStream<Data, Error> { 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 {
Expand Down
6 changes: 4 additions & 2 deletions Sources/GraphQLVapor/WebSocket/WebSocketMessenger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<S: Collection>(_ 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 {
Expand Down
Loading