You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: MIGRATION.md
+26-1Lines changed: 26 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,30 @@
1
1
# Migration
2
2
3
+
## 2.0 to 3.0
4
+
5
+
### NIO removal
6
+
7
+
All NIO-based parameters and return types were removed, including all that used `EventLoopGroup` and `EventLoopFuture`s.
8
+
9
+
As such, all `API.execute` and `API.subscribe` calls should have the `eventLoopGroup` argument removed, and the `await` keyword should be used. If access to an `eventLoopGroup` is required in the resolver, one should be passed via the `Context`.
10
+
11
+
Also, all resolver closures have had the `eventLoopGroup` parameter removed, and all that return an `EventLoopFuture` should be converted to an `async` function.
12
+
13
+
The documentation here may be very helpful in the conversion: https://www.swift.org/documentation/server/guides/libraries/concurrency-adoption-guidelines.html
14
+
15
+
### Swift Concurrency checking
16
+
17
+
With the conversion from NIO to Swift Concurrency, types used across async boundaries should conform to `Sendable` to avoid errors and warnings. This includes the Swift types and functions that back the GraphQL schema, including the `Resolver` and `Context` types. For more details on the conversion, see the [Sendable documentation](https://developer.apple.com/documentation/swift/sendable).
18
+
19
+
### Subscription result changes
20
+
21
+
The `API.subscribe(...)` will return a `Result<AsyncThrowingStream<GraphQLResult, Error>>`, instead of an `EventStream`. This means extracting the stream via a `.stream` call and downcasting to `ConcurrentEventStream` are no longer necessary.
22
+
The `EventStream` and `SubscriptionResult` types have been removed.
23
+
24
+
### GraphQL v4 upgrades
25
+
26
+
See [the GraphQL v4 migration documentation](https://github.com/GraphQLSwift/GraphQL/blob/main/MIGRATION.md#3-to-4) for additional details.
27
+
3
28
## 1.0 to 2.0
4
29
5
30
### TypeReference removal
@@ -36,4 +61,4 @@ The deprecated `Types` type has been removed. Instead define types individually
36
61
### Reflection `isEncodable`
37
62
38
63
The deprecated `Reflection.isEncodable(type: Any.Type) -> Bool` function has been removed. Please re-implement in your
Copy file name to clipboardExpand all lines: README.md
+9-33Lines changed: 9 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# Graphiti
1
+
# Graphiti
2
2
3
3
Graphiti is a Swift library for building GraphQL schemas fast, safely and easily.
4
4
@@ -86,7 +86,7 @@ struct MessageAPI : API {
86
86
let resolver: Resolver
87
87
let schema: Schema<Resolver, Context>
88
88
}
89
-
89
+
90
90
let api =MessageAPI(
91
91
resolver: Resolver()
92
92
schema:try! Schema<Resolver, Context> {
@@ -124,7 +124,7 @@ let api = MessageAPI(
124
124
resolver: Resolver()
125
125
schema: schema
126
126
)
127
-
```
127
+
```
128
128
129
129
</details>
130
130
<details>
@@ -136,7 +136,7 @@ final class ChatSchema: PartialSchema<Resolver, Context> {
136
136
publicoverridevar types: Types {
137
137
Type(Message.self) {
138
138
Field("content", at: \.content)
139
-
}
139
+
}
140
140
}
141
141
142
142
@FieldDefinitions
@@ -152,7 +152,7 @@ let api = MessageAPI(
152
152
resolver: Resolver()
153
153
schema: schema
154
154
)
155
-
```
155
+
```
156
156
157
157
</details>
158
158
@@ -164,7 +164,7 @@ let chatSchema = PartialSchema<Resolver, Context>(
164
164
types: {
165
165
Type(Message.self) {
166
166
Field("content", at: \.content)
167
-
}
167
+
}
168
168
},
169
169
query: {
170
170
Field("message", at: Resolver.message)
@@ -178,7 +178,7 @@ let api = MessageAPI(
178
178
resolver: Resolver()
179
179
schema: schema
180
180
)
181
-
```
181
+
```
182
182
183
183
</details>
184
184
@@ -190,20 +190,10 @@ let api = MessageAPI(
190
190
191
191
#### Querying
192
192
193
-
To query the schema we need to pass in a NIO EventLoopGroup to feed the execute function alongside the query itself.
194
-
195
193
```swift
196
-
importNIO
197
-
198
-
let group =MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
199
-
defer {
200
-
try? group.syncShutdownGracefully()
201
-
}
202
-
203
194
let result =tryawait api.execute(
204
195
request: "{ message { content } }",
205
-
context: Context(),
206
-
on: group
196
+
context: Context()
207
197
)
208
198
print(result)
209
199
```
@@ -228,27 +218,13 @@ struct Resolver {
228
218
}
229
219
```
230
220
231
-
#### NIO resolvers
232
-
233
-
The resolver functions also support `NIO`-style concurrency. To do so, just add one more parameter with type `EventLoopGroup` to the resolver function and change the return type to `EventLoopFuture<YouReturnType>`. Don't forget to import NIO.
This library supports GraphQL subscriptions, and supports them through the Swift Concurrency `AsyncThrowingStream` type. See the [Usage Guide](UsageGuide.md#subscriptions) for details.
248
224
249
225
If you are unable to use Swift Concurrency, you must create a concrete subclass of the `EventStream` class that implements event streaming
250
226
functionality. If you don't feel like creating a subclass yourself, you can use the [GraphQLRxSwift](https://github.com/GraphQLSwift/GraphQLRxSwift) repository
251
-
to integrate [RxSwift](https://github.com/ReactiveX/RxSwift) observables out-of-the-box. Or you can use that repository as a reference to connect a different
227
+
to integrate [RxSwift](https://github.com/ReactiveX/RxSwift) observables out-of-the-box. Or you can use that repository as a reference to connect a different
252
228
stream library like [ReactiveSwift](https://github.com/ReactiveCocoa/ReactiveSwift), [OpenCombine](https://github.com/OpenCombine/OpenCombine), or
0 commit comments