@@ -153,25 +153,28 @@ where
153153 }
154154
155155 if isStreaming {
156+ let stream : SubscriptionSequenceType
156157 do {
157- let stream = try await onSubscribe ( graphQLRequest, initResult)
158- for try await event in stream {
159- try Task . checkCancellation ( )
160- try await self . sendNext ( event, id: id)
161- }
158+ stream = try await onSubscribe ( graphQLRequest, initResult)
162159 } catch {
163160 try await sendError ( error, id: id)
161+ return
164162 }
165- try await self . sendComplete ( id: id)
163+ for try await event in stream {
164+ try await self . sendNext ( event, id: id)
165+ }
166+ executionTasks. removeValue ( forKey: id)
166167 } else {
168+ let result : GraphQLResult
167169 do {
168- let result = try await onExecute ( graphQLRequest, initResult)
169- try await sendNext ( result, id: id)
170- try await sendComplete ( id: id)
170+ result = try await onExecute ( graphQLRequest, initResult)
171171 } catch {
172172 try await sendError ( error, id: id)
173+ return
173174 }
175+ try await sendNext ( result, id: id)
174176 }
177+ try await sendComplete ( id: id)
175178 }
176179 }
177180
@@ -240,11 +243,6 @@ where
240243 try await sendError ( [ error] , id: id)
241244 }
242245
243- /// Send an `error` response through the messenger
244- private func sendError( _ errorMessage: String , id: String ) async throws {
245- try await sendError ( GraphQLError ( message: errorMessage) , id: id)
246- }
247-
248246 /// Send an error through the messenger and close the connection
249247 private func error( _ error: GraphQLTransportWSError ) async throws {
250248 try await messenger. error ( error. message, code: error. code. rawValue)
0 commit comments