@@ -135,12 +135,11 @@ func createSourceEventStream(
135135) -> EventLoopFuture < SourceEventStreamResult > {
136136
137137 let executeStarted = instrumentation. now
138- let exeContext : ExecutionContext
139138
140139 do {
141140 // If a valid context cannot be created due to incorrect arguments,
142141 // this will throw an error.
143- exeContext = try buildExecutionContext (
142+ let exeContext = try buildExecutionContext (
144143 queryStrategy: queryStrategy,
145144 mutationStrategy: mutationStrategy,
146145 subscriptionStrategy: subscriptionStrategy,
@@ -154,6 +153,7 @@ func createSourceEventStream(
154153 operationName: operationName
155154 // TODO shouldn't we be including the subscribeFieldResolver??
156155 )
156+ return try executeSubscription ( context: exeContext, eventLoopGroup: eventLoopGroup)
157157 } catch let error as GraphQLError {
158158 instrumentation. operationExecution (
159159 processId: processId ( ) ,
@@ -174,8 +174,6 @@ func createSourceEventStream(
174174 } catch {
175175 return eventLoopGroup. next ( ) . makeSucceededFuture ( SourceEventStreamResult . failure ( GraphQLError ( error) ) )
176176 }
177-
178- return try ! executeSubscription ( context: exeContext, eventLoopGroup: eventLoopGroup)
179177}
180178
181179func executeSubscription(
@@ -233,45 +231,32 @@ func executeSubscription(
233231
234232 // Get the resolve func, regardless of if its result is normal
235233 // or abrupt (error).
236- let result = resolveOrError (
234+ let resolvedFutureOrError = resolveOrError (
237235 resolve: resolve,
238236 source: context. rootValue,
239237 args: args,
240238 context: contextValue,
241239 eventLoopGroup: eventLoopGroup,
242240 info: info
243241 )
244- return try completeValueCatchingError (
245- exeContext: context,
246- returnType: fieldDef. type,
247- fieldASTs: fieldNodes,
248- info: info,
249- path: path,
250- result: result
251- )
252- // TODO do we need to create this data map?
253- // .flatMapThrowing { data -> Any in
254- // // Translate from raw value completion map into a GraphQLResult
255- // var dataMap: Map = [:]
256- // dataMap[fieldDef.name] = try map(from: data)
257- // var result: GraphQLResult = GraphQLResult(data: dataMap)
258- //
259- // if !context.errors.isEmpty {
260- // result.errors = context.errors
261- // }
262- // return result
263- // }
264- . map { value -> SourceEventStreamResult in
242+
243+ let resolvedFuture : Future < Any ? >
244+ switch resolvedFutureOrError {
245+ case let . failure( error) :
246+ throw error
247+ case let . success( success) :
248+ resolvedFuture = success
249+ }
250+ return resolvedFuture. map { resolved -> SourceEventStreamResult in
265251 if !context. errors. isEmpty {
266252 // TODO improve this to return multiple errors if we have them.
267253 return SourceEventStreamResult . failure ( context. errors. first!)
268- } else if value is Observable < Any ? > {
269- let observable = value as! Observable < Any >
270- return SourceEventStreamResult . success ( observable)
271- } else if let error = value as? GraphQLError {
254+ } else if let error = resolved as? GraphQLError {
272255 return SourceEventStreamResult . failure ( error)
256+ } else if let observable = resolved as? Observable < Any > {
257+ return SourceEventStreamResult . success ( observable)
273258 } else {
274- return SourceEventStreamResult . failure ( GraphQLError ( message: " Subscription field resolver must return Observable of GraphQLResults. " ) )
259+ return SourceEventStreamResult . failure ( GraphQLError ( message: " Subscription field resolver must return an Observable<Any> " ) )
275260 }
276261 }
277262}
0 commit comments