Skip to content

Commit f9bbe01

Browse files
feat!: Uses swift concurrency under the hood
This removes the NIO dependency. It is breaking because it removes all Swift NIO-isms that were present in the public APIs (like EventLoopFuture and EventLoopGroup argument/return types).
1 parent bd5419f commit f9bbe01

29 files changed

+1121
-1824
lines changed

MIGRATION.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
# Migration
22

3-
## 2.0 to 3.0
3+
## 3 to 4
4+
5+
### NIO removal
6+
7+
All NIO-based arguments and return types were removed, including all `EventLoopGroup` and `EventLoopFuture` parameters.
8+
9+
As such, all `execute` and `subscribe` calls should have the `eventLoopGroup` argument removed, and the `await` keyword should be used.
10+
11+
Also, all resolver closures must remove the `eventLoopGroup` argument, and all that return an `EventLoopFuture` should be converted to an `async` function.
12+
13+
The documentation here will be very helpful in the conversion: https://www.swift.org/documentation/server/guides/libraries/concurrency-adoption-guidelines.html
14+
15+
### `ConcurrentDispatchFieldExecutionStrategy`
16+
17+
This was changed to `ConcurrentFieldExecutionStrategy`, and takes no parameters.
18+
19+
## 2 to 3
420

521
### TypeReference removal
622

@@ -73,4 +89,4 @@ The following type properties were changed from arrays to closures. To get the a
7389

7490
### GraphQL type codability
7591

76-
With GraphQL type definitions now including closures, many of the objects in [Definition](https://github.com/GraphQLSwift/GraphQL/blob/main/Sources/GraphQL/Type/Definition.swift) are no longer codable. If you are depending on codability, you can conform the type appropriately in your downstream package.
92+
With GraphQL type definitions now including closures, many of the objects in [Definition](https://github.com/GraphQLSwift/GraphQL/blob/main/Sources/GraphQL/Type/Definition.swift) are no longer codable. If you are depending on codability, you can conform the type appropriately in your downstream package.

Package.resolved

Lines changed: 0 additions & 27 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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@ import PackageDescription
33

44
let package = Package(
55
name: "GraphQL",
6+
platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6)],
67
products: [
78
.library(name: "GraphQL", targets: ["GraphQL"]),
89
],
910
dependencies: [
10-
.package(url: "https://github.com/apple/swift-nio.git", .upToNextMajor(from: "2.10.1")),
1111
.package(url: "https://github.com/apple/swift-collections", .upToNextMajor(from: "1.0.0")),
1212
],
1313
targets: [
1414
.target(
1515
name: "GraphQL",
1616
dependencies: [
17-
.product(name: "NIO", package: "swift-nio"),
1817
.product(name: "OrderedCollections", package: "swift-collections"),
1918
]
2019
),

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ Once a schema has been defined queries may be executed against it using the glob
4545
```swift
4646
let result = try await graphql(
4747
schema: schema,
48-
request: "{ hello }",
49-
eventLoopGroup: eventLoopGroup
48+
request: "{ hello }"
5049
)
5150
```
5251

@@ -59,7 +58,7 @@ The result of this query is a `GraphQLResult` that encodes to the following JSON
5958
### Subscription
6059

6160
This package supports GraphQL subscription, but until the integration of `AsyncSequence` in Swift 5.5 the standard Swift library did not
62-
provide an event-stream construct. For historical reasons and backwards compatibility, this library implements subscriptions using an
61+
provide an event-stream construct. For historical reasons and backwards compatibility, this library implements subscriptions using an
6362
`EventStream` protocol that nearly every asynchronous stream implementation can conform to.
6463

6564
To create a subscription field in a GraphQL schema, use the `subscribe` resolver that returns an `EventStream`. You must also provide a
@@ -70,7 +69,7 @@ let schema = try GraphQLSchema(
7069
subscribe: GraphQLObjectType(
7170
name: "Subscribe",
7271
fields: [
73-
"hello": GraphQLField(
72+
"hello": GraphQLField(
7473
type: GraphQLString,
7574
resolve: { eventResult, _, _, _, _ in // Defines how to transform each event when it occurs
7675
return eventResult
@@ -116,13 +115,13 @@ The example above assumes that your environment has access to Swift Concurrency.
116115

117116
## Encoding Results
118117

119-
If you encode a `GraphQLResult` with an ordinary `JSONEncoder`, there are no guarantees that the field order will match the query,
118+
If you encode a `GraphQLResult` with an ordinary `JSONEncoder`, there are no guarantees that the field order will match the query,
120119
violating the [GraphQL spec](https://spec.graphql.org/June2018/#sec-Serialized-Map-Ordering). To preserve this order, `GraphQLResult`
121120
should be encoded using the `GraphQLJSONEncoder` provided by this package.
122121

123122
## Support
124123

125-
This package supports Swift versions in [alignment with Swift NIO](https://github.com/apple/swift-nio?tab=readme-ov-file#swift-versions).
124+
This package aims to support the previous three Swift versions.
126125

127126
For details on upgrading to new major versions, see [MIGRATION](MIGRATION.md).
128127

@@ -140,7 +139,7 @@ To format your code, install `swiftformat` and run:
140139

141140
```bash
142141
swiftformat .
143-
```
142+
```
144143

145144
Most of this repo mirrors the structure of
146145
(the canonical GraphQL implementation written in Javascript/Typescript)[https://github.com/graphql/graphql-js]. If there is any feature

0 commit comments

Comments
 (0)