Skip to content

Commit 6462f86

Browse files
author
Garrett Moseke
authored
fix: add id parameter for onComplete & onError callbacks
1 parent 2019bc3 commit 6462f86

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

Sources/GraphQLWS/Server.swift

+7-15
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ 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 onOperationComplete: () -> Void = {}
23-
var onOperationError: () -> Void = {}
22+
var onOperationComplete: (String) -> Void = { _ in }
23+
var onOperationError: (String) -> Void = { _ in }
2424

2525
var initialized = false
2626

@@ -87,7 +87,7 @@ public class Server<InitPayload: Equatable & Codable> {
8787
self.error(.invalidRequestFormat(messageType: .GQL_STOP))
8888
return
8989
}
90-
self.onStop(stopRequest, messenger)
90+
self.onOperationComplete(stopRequest.id)
9191
case .GQL_CONNECTION_TERMINATE:
9292
guard let connectionTerminateRequest = try? self.decoder.decode(ConnectionTerminateRequest.self, from: json) else {
9393
self.error(.invalidRequestFormat(messageType: .GQL_CONNECTION_TERMINATE))
@@ -121,13 +121,13 @@ public class Server<InitPayload: Equatable & Codable> {
121121

122122
/// Define the callback run on the completion a full operation (query/mutation, end of subscription)
123123
/// - Parameter callback: The callback to assign
124-
public func onOperationComplete(_ callback: @escaping () -> Void) {
124+
public func onOperationComplete(_ callback: @escaping (String) -> Void) {
125125
self.onOperationComplete = callback
126126
}
127127

128128
/// Define the callback to run on error of any full operation (failed query, interrupted subscription)
129129
/// - Parameter callback: The callback to assign
130-
public func onOperationError(_ callback: @escaping () -> Void) {
130+
public func onOperationError(_ callback: @escaping (String) -> Void) {
131131
self.onOperationError = callback
132132
}
133133

@@ -216,14 +216,6 @@ public class Server<InitPayload: Equatable & Codable> {
216216
}
217217
}
218218

219-
private func onStop(_: StopRequest, _ messenger: Messenger) {
220-
guard initialized else {
221-
self.error(.notInitialized())
222-
return
223-
}
224-
onOperationComplete()
225-
}
226-
227219
private func onConnectionTerminate(_: ConnectionTerminateRequest, _ messenger: Messenger) {
228220
onExit()
229221
_ = messenger.close()
@@ -272,7 +264,7 @@ public class Server<InitPayload: Equatable & Codable> {
272264
id: id
273265
).toJSON(encoder)
274266
)
275-
onOperationComplete()
267+
onOperationComplete(id)
276268
}
277269

278270
/// Send an `error` response through the messenger
@@ -284,7 +276,7 @@ public class Server<InitPayload: Equatable & Codable> {
284276
id: id
285277
).toJSON(encoder)
286278
)
287-
onOperationError()
279+
onOperationError(id)
288280
}
289281

290282
/// Send an `error` response through the messenger

0 commit comments

Comments
 (0)