Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift 6 Compatibility #149

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion Sources/GraphQL/Execution/Execute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ func completeValue(
}
}

return result.flatMap(to: Any?.self) { result -> Future<Any?> in
return result.tryFlatMap { result throws -> Future<Any?> 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)
Expand Down
2 changes: 1 addition & 1 deletion Sources/GraphQL/Execution/Values.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion Sources/GraphQL/GraphQL.swift
Original file line number Diff line number Diff line change
@@ -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]

Expand Down
4 changes: 2 additions & 2 deletions Sources/GraphQL/Map/Map.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public enum MapError: Error {

// MARK: Map

public enum Map {
public enum Map: Sendable {
case undefined
case null
case bool(Bool)
Expand Down Expand Up @@ -600,7 +600,7 @@ public extension Map {
}
}

extension String: CodingKey {
extension Swift.String: Swift.CodingKey {
public var stringValue: String {
return self
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/GraphQL/Map/Number.swift
Original file line number Diff line number Diff line change
@@ -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
Expand Down
38 changes: 2 additions & 36 deletions Sources/GraphQL/Utilities/NIO+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@ public extension Collection {
}
}

extension Collection {
func flatMap<S, T>(
to _: T.Type,
on eventLoopGroup: EventLoopGroup,
_ callback: @escaping ([S]) throws -> Future<T>
) -> Future<T> where Element == Future<S> {
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
Expand Down Expand Up @@ -63,34 +53,10 @@ extension OrderedDictionary where Value: FutureType {
}
}

extension Future {
func flatMap<T>(
to _: T.Type = T.self,
_ callback: @escaping (Expectation) throws -> Future<T>
) -> Future<T> {
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 (Expectation) -> Void)
func whenFailure(_ callback: @escaping (Error) -> Void)
func whenSuccess(_ callback: @escaping @Sendable (Expectation) -> Void)
func whenFailure(_ callback: @escaping @Sendable (Error) -> Void)
func map<NewValue>(
file: StaticString,
line: UInt,
Expand Down
9 changes: 0 additions & 9 deletions Tests/GraphQLTests/LanguageTests/LexerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions Tests/GraphQLTests/SubscriptionTests/SubscriptionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading