Skip to content

Commit 45629e4

Browse files
authored
Merge pull request #57 from eliotfowler/upgrade-nio-to-2.10
Upgrade Swift-NIO to 2.10.1 and fix related errors and warnings
2 parents 02e6a51 + 53577f9 commit 45629e4

File tree

8 files changed

+47
-54
lines changed

8 files changed

+47
-54
lines changed

Package.resolved

Lines changed: 2 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let package = Package(
77
.library(name: "GraphQL", targets: ["GraphQL"]),
88
],
99
dependencies: [
10-
.package(url: "https://github.com/apple/swift-nio.git", .upToNextMajor(from: "1.14.1")),
10+
.package(url: "https://github.com/apple/swift-nio.git", .upToNextMajor(from: "2.10.1")),
1111
.package(url: "https://github.com/wickwirew/Runtime.git", .upToNextMinor(from: "2.1.0"))
1212
],
1313
targets: [

Sources/GraphQL/Execution/Execute.swift

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,9 @@ func execute(
273273
result: nil
274274
)
275275

276-
return eventLoopGroup.next().newSucceededFuture(result: GraphQLResult(errors: [error]))
276+
return eventLoopGroup.next().makeSucceededFuture(GraphQLResult(errors: [error]))
277277
} catch {
278-
return eventLoopGroup.next().newSucceededFuture(result: GraphQLResult(errors: [GraphQLError(error)]))
278+
return eventLoopGroup.next().makeSucceededFuture(GraphQLResult(errors: [GraphQLError(error)]))
279279
}
280280

281281
do {
@@ -285,7 +285,7 @@ func execute(
285285
exeContext: buildContext,
286286
operation: buildContext.operation,
287287
rootValue: rootValue
288-
).thenThrowing { data -> GraphQLResult in
288+
).flatMapThrowing { data -> GraphQLResult in
289289
var dataMap: Map = [:]
290290

291291
for (key, value) in data {
@@ -300,12 +300,15 @@ func execute(
300300

301301
// executeErrors = buildContext.errors
302302
return result
303-
}.mapIfError { error -> GraphQLResult in
303+
}.flatMapError { error -> Future<GraphQLResult> in
304+
let result: GraphQLResult
304305
if let error = error as? GraphQLError {
305-
return GraphQLResult(errors: [error])
306+
result = GraphQLResult(errors: [error])
307+
} else {
308+
result = GraphQLResult(errors: [GraphQLError(error)])
306309
}
307310

308-
return GraphQLResult(errors: [GraphQLError(error)])
311+
return buildContext.eventLoopGroup.next().makeSucceededFuture(result)
309312
}.map { result -> GraphQLResult in
310313
// instrumentation.operationExecution(
311314
// processId: processId(),
@@ -325,9 +328,9 @@ func execute(
325328
return result
326329
}
327330
} catch let error as GraphQLError {
328-
return eventLoopGroup.next().newSucceededFuture(result: GraphQLResult(errors: [error]))
331+
return eventLoopGroup.next().makeSucceededFuture(GraphQLResult(errors: [error]))
329332
} catch {
330-
return eventLoopGroup.next().newSucceededFuture(result: GraphQLResult(errors: [GraphQLError(error)]))
333+
return eventLoopGroup.next().makeSucceededFuture(GraphQLResult(errors: [GraphQLError(error)]))
331334
}
332335
}
333336

@@ -788,20 +791,20 @@ func completeValueCatchingError(
788791
info: info,
789792
path: path,
790793
result: result
791-
).mapIfError { error -> Any? in
794+
).flatMapError { error -> EventLoopFuture<Any?> in
792795
guard let error = error as? GraphQLError else {
793796
fatalError()
794797
}
795798
exeContext.append(error: error)
796-
return nil
799+
return exeContext.eventLoopGroup.next().makeSucceededFuture(nil)
797800
}
798801

799802
return completed
800803
} catch let error as GraphQLError {
801804
// If `completeValueWithLocatedError` returned abruptly (threw an error),
802805
// log the error and return .null.
803806
exeContext.append(error: error)
804-
return exeContext.eventLoopGroup.next().newSucceededFuture(result: nil)
807+
return exeContext.eventLoopGroup.next().makeSucceededFuture(nil)
805808
} catch {
806809
fatalError()
807810
}
@@ -825,7 +828,7 @@ func completeValueWithLocatedError(
825828
info: info,
826829
path: path,
827830
result: result
828-
).thenIfErrorThrowing { error -> Any? in
831+
).flatMapErrorThrowing { error -> Any? in
829832
throw locatedError(originalError: error, nodes: fieldASTs, path: path)
830833
}
831834
return completed
@@ -881,7 +884,7 @@ func completeValue(
881884
info: info,
882885
path: path,
883886
result: .success(result)
884-
).thenThrowing { value -> Any? in
887+
).flatMapThrowing { value -> Any? in
885888
guard let value = value else {
886889
throw GraphQLError(message: "Cannot return null for non-nullable field \(info.parentType.name).\(info.fieldName).")
887890
}
@@ -893,7 +896,7 @@ func completeValue(
893896
return result.flatMap(to: Any?.self) { result -> Future<Any?> in
894897
// If result value is null-ish (nil or .null) then return .null.
895898
guard let result = result, let r = unwrap(result) else {
896-
return exeContext.eventLoopGroup.next().newSucceededFuture(result: nil)
899+
return exeContext.eventLoopGroup.next().makeSucceededFuture(nil)
897900
}
898901

899902
// If field type is List, complete each item in the list with the inner type
@@ -911,7 +914,7 @@ func completeValue(
911914
// If field type is a leaf type, Scalar or Enum, serialize to a valid value,
912915
// returning .null if serialization is not possible.
913916
if let returnType = returnType as? GraphQLLeafType {
914-
return exeContext.eventLoopGroup.next().newSucceededFuture(result: try completeLeafValue(returnType: returnType, result: r))
917+
return exeContext.eventLoopGroup.next().makeSucceededFuture(try completeLeafValue(returnType: returnType, result: r))
915918
}
916919

917920
// If field type is an abstract type, Interface or Union, determine the
@@ -972,7 +975,7 @@ func completeListValue(
972975
// No need to modify the info object containing the path,
973976
// since from here on it is not ever accessed by resolver funcs.
974977
let fieldPath = path.appending(index)
975-
let futureItem = item as? Future<Any?> ?? exeContext.eventLoopGroup.next().newSucceededFuture(result: item)
978+
let futureItem = item as? Future<Any?> ?? exeContext.eventLoopGroup.next().makeSucceededFuture(item)
976979

977980
let completedItem = try completeValueCatchingError(
978981
exeContext: exeContext,
@@ -1161,30 +1164,30 @@ func defaultResolve(
11611164
info: GraphQLResolveInfo
11621165
) -> Future<Any?> {
11631166
guard let source = unwrap(source) else {
1164-
return eventLoopGroup.next().newSucceededFuture(result: nil)
1167+
return eventLoopGroup.next().makeSucceededFuture(nil)
11651168
}
11661169

11671170
if let subscriptable = source as? KeySubscriptable {
11681171
let value = subscriptable[info.fieldName]
1169-
return eventLoopGroup.next().newSucceededFuture(result: value)
1172+
return eventLoopGroup.next().makeSucceededFuture(value)
11701173
}
11711174

11721175
guard let encodable = source as? Encodable else {
1173-
return eventLoopGroup.next().newSucceededFuture(result: nil)
1176+
return eventLoopGroup.next().makeSucceededFuture(nil)
11741177
}
11751178

11761179
guard
11771180
let typeInfo = try? typeInfo(of: type(of: encodable)),
11781181
let property = try? typeInfo.property(named: info.fieldName)
11791182
else {
1180-
return eventLoopGroup.next().newSucceededFuture(result: nil)
1183+
return eventLoopGroup.next().makeSucceededFuture(nil)
11811184
}
11821185

11831186
guard let value = try? property.get(from: encodable) else {
1184-
return eventLoopGroup.next().newSucceededFuture(result: nil)
1187+
return eventLoopGroup.next().makeSucceededFuture(nil)
11851188
}
11861189

1187-
return eventLoopGroup.next().newSucceededFuture(result: value)
1190+
return eventLoopGroup.next().makeSucceededFuture(value)
11881191

11891192
// guard let any = try? AnyEncoder().encode(AnyEncodable(encodable)) else {
11901193
// return eventLoopGroup.next().newSucceededFuture(result: nil)

Sources/GraphQL/GraphQL.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public func graphql(
8080
let validationErrors = validate(instrumentation: instrumentation, schema: schema, ast: documentAST)
8181

8282
guard validationErrors.isEmpty else {
83-
return eventLoopGroup.next().newSucceededFuture(result: GraphQLResult(errors: validationErrors))
83+
return eventLoopGroup.next().makeSucceededFuture(GraphQLResult(errors: validationErrors))
8484
}
8585

8686
return execute(
@@ -134,7 +134,7 @@ public func graphql<Retrieval: PersistedQueryRetrieval>(
134134
case .parseError(let parseError):
135135
throw parseError
136136
case .validateErrors(_, let validationErrors):
137-
return eventLoopGroup.next().newSucceededFuture(result: GraphQLResult(errors: validationErrors))
137+
return eventLoopGroup.next().makeSucceededFuture(GraphQLResult(errors: validationErrors))
138138
case .result(let schema, let documentAST):
139139
return execute(
140140
queryStrategy: queryStrategy,

Sources/GraphQL/Type/Definition.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ public struct GraphQLField {
557557

558558
self.resolve = { source, args, context, eventLoopGroup, info in
559559
let result = try resolve(source, args, context, info)
560-
return eventLoopGroup.next().newSucceededFuture(result: result)
560+
return eventLoopGroup.next().makeSucceededFuture(result)
561561
}
562562
}
563563
}

Sources/GraphQL/Type/Introspection.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ let SchemaMetaFieldDef = GraphQLFieldDefinition(
445445
type: GraphQLNonNull(__Schema),
446446
description: "Access the current type schema of this server.",
447447
resolve: { _, _, _, eventLoopGroup, info in
448-
return eventLoopGroup.next().newSucceededFuture(result: info.schema)
448+
return eventLoopGroup.next().makeSucceededFuture(info.schema)
449449
}
450450
)
451451

@@ -461,7 +461,7 @@ let TypeMetaFieldDef = GraphQLFieldDefinition(
461461
],
462462
resolve: { _, arguments, _, eventLoopGroup, info in
463463
let name = arguments["name"].string!
464-
return eventLoopGroup.next().newSucceededFuture(result: info.schema.getType(name: name))
464+
return eventLoopGroup.next().makeSucceededFuture(info.schema.getType(name: name))
465465
}
466466
)
467467

@@ -470,6 +470,6 @@ let TypeNameMetaFieldDef = GraphQLFieldDefinition(
470470
type: GraphQLNonNull(GraphQLString),
471471
description: "The name of the current Object type at runtime.",
472472
resolve: { _, _, _, eventLoopGroup, info in
473-
eventLoopGroup.next().newSucceededFuture(result: info.parentType.name)
473+
eventLoopGroup.next().makeSucceededFuture(info.parentType.name)
474474
}
475475
)

Sources/GraphQL/Utilities/NIO+Extensions.swift

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import NIO
1111
public typealias Future = EventLoopFuture
1212

1313
extension Collection {
14-
internal func flatten<T>(on eventLoopGroup: EventLoopGroup) -> Future<[T]> where Element == Future<T> {
15-
return Future.whenAll(Array(self), eventLoop: eventLoopGroup.next())
14+
public func flatten<T>(on eventLoopGroup: EventLoopGroup) -> Future<[T]> where Element == Future<T> {
15+
return Future.whenAllSucceed(Array(self), on: eventLoopGroup.next())
1616
}
1717
}
1818

@@ -31,23 +31,23 @@ extension Dictionary where Value : FutureType {
3131
var elements: [Key: Value.Expectation] = [:]
3232

3333
guard self.count > 0 else {
34-
return eventLoopGroup.next().newSucceededFuture(result: elements)
34+
return eventLoopGroup.next().makeSucceededFuture(elements)
3535
}
3636

37-
let promise: EventLoopPromise<[Key: Value.Expectation]> = eventLoopGroup.next().newPromise()
37+
let promise: EventLoopPromise<[Key: Value.Expectation]> = eventLoopGroup.next().makePromise()
3838
elements.reserveCapacity(self.count)
3939

4040
for (key, value) in self {
4141
value.whenSuccess { expectation in
4242
elements[key] = expectation
4343

4444
if elements.count == self.count {
45-
promise.succeed(result: elements)
45+
promise.succeed(elements)
4646
}
4747
}
4848

4949
value.whenFailure { error in
50-
promise.fail(error: error)
50+
promise.fail(error)
5151
}
5252
}
5353

@@ -59,19 +59,19 @@ extension Future {
5959
to type: T.Type = T.self,
6060
_ callback: @escaping (Expectation) throws -> Future<T>
6161
) -> Future<T> {
62-
let promise = eventLoop.newPromise(of: T.self)
62+
let promise = eventLoop.makePromise(of: T.self)
6363

6464
self.whenSuccess { expectation in
6565
do {
6666
let mapped = try callback(expectation)
67-
mapped.cascade(promise: promise)
67+
mapped.cascade(to: promise)
6868
} catch {
69-
promise.fail(error: error)
69+
promise.fail(error)
7070
}
7171
}
7272

7373
self.whenFailure { error in
74-
promise.fail(error: error)
74+
promise.fail(error)
7575
}
7676

7777
return promise.futureResult
@@ -85,6 +85,5 @@ public protocol FutureType {
8585
}
8686

8787
extension Future : FutureType {
88-
public typealias Expectation = T
89-
88+
public typealias Expectation = Value
9089
}

Tests/GraphQLTests/FieldExecutionStrategyTests/FieldExecutionStrategyTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class FieldExecutionStrategyTests: XCTestCase {
2323
}
2424

2525
group.wait()
26-
return eventLoopGroup.next().newSucceededFuture(result: "z")
26+
return eventLoopGroup.next().makeSucceededFuture("z")
2727
}
2828
),
2929
"bang": GraphQLField(
@@ -55,7 +55,7 @@ class FieldExecutionStrategyTests: XCTestCase {
5555

5656
g.wait()
5757

58-
return eventLoopGroup.next().newFailedFuture(error: StrategyError.exampleError(
58+
return eventLoopGroup.next().makeFailedFuture(StrategyError.exampleError(
5959
msg: "\(info.fieldName): \(info.path.elements.last!)"
6060
))
6161
}

0 commit comments

Comments
 (0)