@@ -59,15 +59,15 @@ func subscribe(
5959 return sourceFuture. map { subscriptionResult -> SubscriptionResult in
6060 do {
6161 let subscriptionObserver = try subscriptionResult. get ( )
62- let eventObserver = subscriptionObserver. map { eventPayload -> GraphQLResult in
62+ let eventObserver = subscriptionObserver. map { eventPayload -> Future < GraphQLResult > in
6363
6464 // For each payload yielded from a subscription, map it over the normal
6565 // GraphQL `execute` function, with `payload` as the rootValue.
6666 // This implements the "MapSourceToResponseEvent" algorithm described in
6767 // the GraphQL specification. The `execute` function provides the
6868 // "ExecuteSubscriptionEvent" algorithm, as it is nearly identical to the
6969 // "ExecuteQuery" algorithm, for which `execute` is also used.
70- let eventResolved = try execute (
70+ return execute (
7171 queryStrategy: queryStrategy,
7272 mutationStrategy: mutationStrategy,
7373 subscriptionStrategy: subscriptionStrategy,
@@ -79,10 +79,8 @@ func subscribe(
7979 eventLoopGroup: eventLoopGroup,
8080 variableValues: variableValues,
8181 operationName: operationName
82- ) . wait ( ) // TODO remove this wait
83- return eventResolved
82+ )
8483 }
85- // TODO Making a future here feels it indicates a mistake...
8684 return SubscriptionResult . success ( eventObserver)
8785 } catch let graphQLError as GraphQLError {
8886 return SubscriptionResult . failure ( graphQLError)
@@ -253,19 +251,21 @@ func executeSubscription(
253251 return SourceEventStreamResult . failure ( context. errors. first!)
254252 } else if let error = resolved as? GraphQLError {
255253 return SourceEventStreamResult . failure ( error)
256- } else if let observable = resolved as? Observable < Any > {
254+ } else if let observable = resolved as? SourceEventStreamObservable {
257255 return SourceEventStreamResult . success ( observable)
258256 } else if resolved == nil {
259257 return SourceEventStreamResult . failure (
260258 GraphQLError ( message: " Resolved subscription was nil " )
261259 )
262260 } else {
263261 return SourceEventStreamResult . failure (
264- GraphQLError ( message: " Subscription field resolver must return an Observable<Any> , not \( Swift . type ( of: resolved) ) " )
262+ GraphQLError ( message: " Subscription field resolver must return an SourceEventStreamObservable , not \( Swift . type ( of: resolved) ) " )
265263 )
266264 }
267265 }
268266}
269267
270- typealias SubscriptionResult = Result < Observable < GraphQLResult > , GraphQLError >
271- typealias SourceEventStreamResult = Result < Observable < Any > , GraphQLError >
268+ typealias SubscriptionObservable = Observable < Future < GraphQLResult > >
269+ typealias SubscriptionResult = Result < SubscriptionObservable , GraphQLError >
270+ typealias SourceEventStreamObservable = Observable < Any >
271+ typealias SourceEventStreamResult = Result < SourceEventStreamObservable , GraphQLError >
0 commit comments