Skip to content

Commit

Permalink
Add ping/pong message support required by graphql-ws
Browse files Browse the repository at this point in the history
  • Loading branch information
calvincestari committed Feb 22, 2022
1 parent 37336c5 commit 348dcf0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Sources/ApolloWebSocket/OperationMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ final class OperationMessage {
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 Down
9 changes: 8 additions & 1 deletion Sources/ApolloWebSocket/WebSocketTransport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,16 @@ 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,
Expand Down

0 comments on commit 348dcf0

Please sign in to comment.