Skip to content

Commit bf739f5

Browse files
author
Garrett Moseke
authored
fix: expose onTop callback handler
1 parent f051242 commit bf739f5

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Sources/GraphQLWS/Server.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class Server<InitPayload: Equatable & Codable> {
1919
var auth: (InitPayload) throws -> Void = { _ in }
2020
var onExit: () -> Void = { }
2121
var onMessage: (String) -> Void = { _ in }
22+
var onStop: () -> Void = { }
2223

2324
var initialized = false
2425

@@ -66,6 +67,7 @@ public class Server<InitPayload: Equatable & Codable> {
6667
return
6768
}
6869

70+
// handle incoming message
6971
switch request.type {
7072
case .GQL_CONNECTION_INIT:
7173
guard let connectionInitRequest = try? self.decoder.decode(ConnectionInitRequest<InitPayload>.self, from: json) else {
@@ -116,6 +118,12 @@ public class Server<InitPayload: Equatable & Codable> {
116118
self.onMessage = callback
117119
}
118120

121+
/// Define the callback run on receipt of a`GQL_STOP` message
122+
/// - Parameter callback: The callback to assign
123+
public func onStop(_ callback: @escaping () -> Void) {
124+
self.onStop = callback
125+
}
126+
119127
private func onConnectionInit(_ connectionInitRequest: ConnectionInitRequest<InitPayload>, _ messenger: Messenger) {
120128
guard !initialized else {
121129
self.error(.tooManyInitializations())
@@ -206,6 +214,7 @@ public class Server<InitPayload: Equatable & Codable> {
206214
self.error(.notInitialized())
207215
return
208216
}
217+
onStop()
209218
}
210219

211220
private func onConnectionTerminate(_: ConnectionTerminateRequest, _ messenger: Messenger) {

0 commit comments

Comments
 (0)