Skip to content

Commit 15a5084

Browse files
author
Garrett Moseke
committed
fix: add onComplete callback
1 parent 5050078 commit 15a5084

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Sources/GraphQLTransportWS/Server.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import GraphQLRxSwift
66
import NIO
77
import RxSwift
88

9-
/// Server implements the server-side portion of the protocol, allowing a few callbacks for customization.
9+
/// Server implements the server-side portion of the protocol, allowing a few callbacks for customization. 0 or 1 subscriptions per connection and no more.
1010
///
1111
/// By default, there are no authorization checks
1212
public class Server<InitPayload: Equatable & Codable> {
@@ -18,6 +18,7 @@ public class Server<InitPayload: Equatable & Codable> {
1818

1919
var auth: (InitPayload) throws -> Void = { _ in }
2020
var onExit: () -> Void = { }
21+
var onComplete: () -> Void = {}
2122
var onMessage: (String) -> Void = { _ in }
2223

2324
var initialized = false
@@ -64,6 +65,7 @@ public class Server<InitPayload: Equatable & Codable> {
6465
return
6566
}
6667

68+
// handle incoing message
6769
switch request.type {
6870
case .connectionInit:
6971
guard let connectionInitRequest = try? self.decoder.decode(ConnectionInitRequest<InitPayload>.self, from: data) else {
@@ -107,6 +109,12 @@ public class Server<InitPayload: Equatable & Codable> {
107109
self.onMessage = callback
108110
}
109111

112+
/// Define the callback run on receipt of a `complete` message
113+
/// - Parameter callback: The callback to assign
114+
public func onComplete(_ callback: @escaping () -> Void) {
115+
self.onComplete = callback
116+
}
117+
110118
private func onConnectionInit(_ connectionInitRequest: ConnectionInitRequest<InitPayload>) {
111119
guard !initialized else {
112120
self.error(.tooManyInitializations())
@@ -198,6 +206,7 @@ public class Server<InitPayload: Equatable & Codable> {
198206
self.error(.notInitialized())
199207
return
200208
}
209+
onComplete()
201210
}
202211

203212
/// Send a `connection_ack` response through the messenger

0 commit comments

Comments
 (0)