From 3f347aeabc7e0e31a1ca22a47f640da4468df8d7 Mon Sep 17 00:00:00 2001 From: Jay Herron Date: Wed, 15 Jan 2025 22:42:11 -0700 Subject: [PATCH] chore: Remove unnecessary funcs --- Sources/GraphQL/Execution/Execute.swift | 2 +- .../GraphQL/Utilities/NIO+Extensions.swift | 34 ------------------- 2 files changed, 1 insertion(+), 35 deletions(-) diff --git a/Sources/GraphQL/Execution/Execute.swift b/Sources/GraphQL/Execution/Execute.swift index 7794f1c7..f082b721 100644 --- a/Sources/GraphQL/Execution/Execute.swift +++ b/Sources/GraphQL/Execution/Execute.swift @@ -919,7 +919,7 @@ func completeValue( } } - return result.flatMap(to: Any?.self) { result -> Future in + return result.tryFlatMap { result throws -> Future in // If result value is null-ish (nil or .null) then return .null. guard let result = result, let r = unwrap(result) else { return exeContext.eventLoopGroup.next().makeSucceededFuture(nil) diff --git a/Sources/GraphQL/Utilities/NIO+Extensions.swift b/Sources/GraphQL/Utilities/NIO+Extensions.swift index 97596ba7..2131551a 100644 --- a/Sources/GraphQL/Utilities/NIO+Extensions.swift +++ b/Sources/GraphQL/Utilities/NIO+Extensions.swift @@ -17,16 +17,6 @@ public extension Collection { } } -extension Collection { - func flatMap( - to _: T.Type, - on eventLoopGroup: EventLoopGroup, - _ callback: @escaping ([S]) throws -> Future - ) -> Future where Element == Future { - return flatten(on: eventLoopGroup).flatMap(to: T.self, callback) - } -} - extension Dictionary where Value: FutureType { func flatten(on eventLoopGroup: EventLoopGroup) -> Future<[Key: Value.Expectation]> { // create array of futures with (key,value) tuple @@ -63,30 +53,6 @@ extension OrderedDictionary where Value: FutureType { } } -extension Future { - func flatMap( - to _: T.Type = T.self, - _ callback: @escaping (Expectation) throws -> Future - ) -> Future { - let promise = eventLoop.makePromise(of: T.self) - - whenSuccess { expectation in - do { - let mapped = try callback(expectation) - mapped.cascade(to: promise) - } catch { - promise.fail(error) - } - } - - whenFailure { error in - promise.fail(error) - } - - return promise.futureResult - } -} - public protocol FutureType { associatedtype Expectation func whenSuccess(_ callback: @escaping @Sendable (Expectation) -> Void)