@@ -19,7 +19,8 @@ public class Server<InitPayload: Equatable & Codable> {
19
19
var auth : ( InitPayload ) throws -> Void = { _ in }
20
20
var onExit : ( ) -> Void = { }
21
21
var onMessage : ( String ) -> Void = { _ in }
22
- var onStop : ( ) -> Void = { }
22
+ var onOperationComplete : ( ) -> Void = { }
23
+ var onOperationError : ( ) -> Void = { }
23
24
24
25
var initialized = false
25
26
@@ -118,10 +119,16 @@ public class Server<InitPayload: Equatable & Codable> {
118
119
self . onMessage = callback
119
120
}
120
121
121
- /// Define the callback run on receipt of a`GQL_STOP` message
122
+ /// Define the callback run on the completion a full operation (query/mutation, end of subscription)
122
123
/// - Parameter callback: The callback to assign
123
- public func onStop( _ callback: @escaping ( ) -> Void ) {
124
- self . onStop = callback
124
+ public func onOperationComplete( _ callback: @escaping ( ) -> Void ) {
125
+ self . onOperationComplete = callback
126
+ }
127
+
128
+ /// Define the callback to run on error of any full operation (failed query, interrupted subscription)
129
+ /// - Parameter callback: The callback to assign
130
+ public func onOperationError( _ callback: @escaping ( ) -> Void ) {
131
+ self . onOperationError = callback
125
132
}
126
133
127
134
private func onConnectionInit( _ connectionInitRequest: ConnectionInitRequest < InitPayload > , _ messenger: Messenger ) {
@@ -214,7 +221,7 @@ public class Server<InitPayload: Equatable & Codable> {
214
221
self . error ( . notInitialized( ) )
215
222
return
216
223
}
217
- onStop ( )
224
+ onOperationComplete ( )
218
225
}
219
226
220
227
private func onConnectionTerminate( _: ConnectionTerminateRequest , _ messenger: Messenger ) {
@@ -265,6 +272,7 @@ public class Server<InitPayload: Equatable & Codable> {
265
272
id: id
266
273
) . toJSON ( encoder)
267
274
)
275
+ onOperationComplete ( )
268
276
}
269
277
270
278
/// Send an `error` response through the messenger
@@ -276,6 +284,7 @@ public class Server<InitPayload: Equatable & Codable> {
276
284
id: id
277
285
) . toJSON ( encoder)
278
286
)
287
+ onOperationError ( )
279
288
}
280
289
281
290
/// Send an `error` response through the messenger
0 commit comments