From 611d9452f2de38bbc426af9d7f9679d5421450de Mon Sep 17 00:00:00 2001 From: Jay Herron Date: Wed, 15 Jan 2025 22:41:20 -0700 Subject: [PATCH 1/4] chore: Remove Swift 6 warnings --- Sources/GraphQL/Execution/Values.swift | 2 +- Sources/GraphQL/GraphQL.swift | 2 +- Sources/GraphQL/Map/Map.swift | 4 ++-- Sources/GraphQL/Map/Number.swift | 6 +++--- Sources/GraphQL/Utilities/NIO+Extensions.swift | 4 ++-- .../GraphQLTests/SubscriptionTests/SubscriptionTests.swift | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Sources/GraphQL/Execution/Values.swift b/Sources/GraphQL/Execution/Values.swift index 4de6e2c9..64724c44 100644 --- a/Sources/GraphQL/Execution/Values.swift +++ b/Sources/GraphQL/Execution/Values.swift @@ -88,7 +88,7 @@ func getVariableValue( definitionAST: VariableDefinition, input: Map ) throws -> Map { - var type = typeFromAST(schema: schema, inputTypeAST: definitionAST.type) + let type = typeFromAST(schema: schema, inputTypeAST: definitionAST.type) let variable = definitionAST.variable guard let inputType = type as? GraphQLInputType else { diff --git a/Sources/GraphQL/GraphQL.swift b/Sources/GraphQL/GraphQL.swift index 76138126..0cc6c643 100644 --- a/Sources/GraphQL/GraphQL.swift +++ b/Sources/GraphQL/GraphQL.swift @@ -1,6 +1,6 @@ import NIO -public struct GraphQLResult: Equatable, Codable, CustomStringConvertible { +public struct GraphQLResult: Equatable, Codable, Sendable, CustomStringConvertible { public var data: Map? public var errors: [GraphQLError] diff --git a/Sources/GraphQL/Map/Map.swift b/Sources/GraphQL/Map/Map.swift index 84ca2d21..fbe751bc 100644 --- a/Sources/GraphQL/Map/Map.swift +++ b/Sources/GraphQL/Map/Map.swift @@ -11,7 +11,7 @@ public enum MapError: Error { // MARK: Map -public enum Map { +public enum Map: Sendable { case undefined case null case bool(Bool) @@ -600,7 +600,7 @@ public extension Map { } } -extension String: CodingKey { +extension Swift.String: Swift.CodingKey { public var stringValue: String { return self } diff --git a/Sources/GraphQL/Map/Number.swift b/Sources/GraphQL/Map/Number.swift index f7633b2a..f711cb27 100644 --- a/Sources/GraphQL/Map/Number.swift +++ b/Sources/GraphQL/Map/Number.swift @@ -1,7 +1,7 @@ -import Foundation +@preconcurrency import Foundation -public struct Number { - public enum StorageType { +public struct Number: Sendable { + public enum StorageType: Sendable { case bool case int case double diff --git a/Sources/GraphQL/Utilities/NIO+Extensions.swift b/Sources/GraphQL/Utilities/NIO+Extensions.swift index 3903fb7f..97596ba7 100644 --- a/Sources/GraphQL/Utilities/NIO+Extensions.swift +++ b/Sources/GraphQL/Utilities/NIO+Extensions.swift @@ -89,8 +89,8 @@ extension Future { public protocol FutureType { associatedtype Expectation - func whenSuccess(_ callback: @escaping (Expectation) -> Void) - func whenFailure(_ callback: @escaping (Error) -> Void) + func whenSuccess(_ callback: @escaping @Sendable (Expectation) -> Void) + func whenFailure(_ callback: @escaping @Sendable (Error) -> Void) func map( file: StaticString, line: UInt, diff --git a/Tests/GraphQLTests/SubscriptionTests/SubscriptionTests.swift b/Tests/GraphQLTests/SubscriptionTests/SubscriptionTests.swift index 57a4273e..db0ebfb6 100644 --- a/Tests/GraphQLTests/SubscriptionTests/SubscriptionTests.swift +++ b/Tests/GraphQLTests/SubscriptionTests/SubscriptionTests.swift @@ -28,11 +28,11 @@ class SubscriptionTests: XCTestCase { } """ - let subscriptionResult = try graphqlSubscribe( + let subscriptionResult = try await graphqlSubscribe( schema: schema, request: query, eventLoopGroup: eventLoopGroup - ).wait() + ).get() guard let subscription = subscriptionResult.stream else { XCTFail(subscriptionResult.errors.description) return From 60c980a4121d92adab26b75c69a84a7a0b0e855c Mon Sep 17 00:00:00 2001 From: Jay Herron Date: Wed, 15 Jan 2025 22:42:11 -0700 Subject: [PATCH 2/4] 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) From 767ca7f95c17c894dee8c05b59d618254bafb71b Mon Sep 17 00:00:00 2001 From: Jay Herron Date: Sat, 21 Sep 2024 09:18:41 -0600 Subject: [PATCH 3/4] ci: Adds 6.0 to test matrix --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e13cce2a..d26e8fad 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -69,7 +69,7 @@ jobs: runs-on: ubuntu-22.04 strategy: matrix: - swift: ["5.8", "5.9", "5.10"] + swift: ["5.8", "5.9", "5.10", "6.0"] steps: - uses: swift-actions/setup-swift@v2 with: From 52088aab34776578428fc5b3e1033902e488816d Mon Sep 17 00:00:00 2001 From: Jay Herron Date: Sun, 19 Jan 2025 14:58:49 -0700 Subject: [PATCH 4/4] test: Removes `measure` test This test is creates unreliable CI since we can't ensure performance of the runner machine. --- Tests/GraphQLTests/LanguageTests/LexerTests.swift | 9 --------- 1 file changed, 9 deletions(-) diff --git a/Tests/GraphQLTests/LanguageTests/LexerTests.swift b/Tests/GraphQLTests/LanguageTests/LexerTests.swift index 5b20744d..c7257c38 100644 --- a/Tests/GraphQLTests/LanguageTests/LexerTests.swift +++ b/Tests/GraphQLTests/LanguageTests/LexerTests.swift @@ -214,15 +214,6 @@ class LexerTests: XCTestCase { XCTAssertEqual(token, expected) } - func testLongStrings() throws { - measure { - let token = try! lexOne("\"\(String(repeating: "123456", count: 10000))\"") - - XCTAssertEqual(token.start, 0) - XCTAssertEqual(token.end, 60002) - } - } - func testStringErrors() throws { XCTAssertThrowsError(try lexOne("\"")) // "Syntax Error GraphQL (1:2) Unterminated string"