@@ -153,25 +153,29 @@ 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 Task . checkCancellation ( )
165+ try await self . sendNext ( event, id: id)
166+ }
167+ executionTasks. removeValue ( forKey: id)
166168 } else {
169+ let result : GraphQLResult
167170 do {
168- let result = try await onExecute ( graphQLRequest, initResult)
169- try await sendNext ( result, id: id)
170- try await sendComplete ( id: id)
171+ result = try await onExecute ( graphQLRequest, initResult)
171172 } catch {
172173 try await sendError ( error, id: id)
174+ return
173175 }
176+ try await sendNext ( result, id: id)
174177 }
178+ try await sendComplete ( id: id)
175179 }
176180 }
177181
@@ -240,11 +244,6 @@ where
240244 try await sendError ( [ error] , id: id)
241245 }
242246
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-
248247 /// Send an error through the messenger and close the connection
249248 private func error( _ error: GraphQLTransportWSError ) async throws {
250249 try await messenger. error ( error. message, code: error. code. rawValue)
0 commit comments