Skip to content

Commit e896a76

Browse files
fix: Adds explicit @Sendable for Swift 6.0
1 parent 0a03c6e commit e896a76

2 files changed

Lines changed: 18 additions & 17 deletions

File tree

Sources/GraphQLGeneratorCore/Generator/BuildGraphQLSchemaGenerator.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,16 +184,17 @@ package struct BuildGraphQLSchemaGenerator {
184184
) throws -> String {
185185
var output = ""
186186

187+
// TODO: Swift 6.0 requires `@Sendable` explicitly here. We can remove it when we drop 6.0 support.
187188
if target == .subscription {
188189
output += """
189-
\(variableName)["\(fieldName)"]?.resolve = { source, _, _, _ in
190+
\(variableName)["\(fieldName)"]?.resolve = { @Sendable source, _, _, _ in
190191
return source
191192
}
192-
\(variableName)["\(fieldName)"]?.subscribe = { source, args, context, info in
193+
\(variableName)["\(fieldName)"]?.subscribe = { @Sendable source, args, context, info in
193194
"""
194195
} else {
195196
output += """
196-
\(variableName)["\(fieldName)"]?.resolve = { source, args, context, info in
197+
\(variableName)["\(fieldName)"]?.resolve = { @Sendable source, args, context, info in
197198
"""
198199
}
199200

Tests/GraphQLGeneratorCoreTests/SchemaGeneratorTests.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ struct SchemaGeneratorTests {
5454
5555
let bar = schema.typeMap["Bar"] as? GraphQLObjectType
5656
let barFields = try bar?.fields() ?? [:]
57-
barFields["foo"]?.resolve = { source, args, context, info in
57+
barFields["foo"]?.resolve = { @Sendable source, args, context, info in
5858
let parent = try cast(source, to: (any GraphQLGenerated.Bar).self)
5959
let context = try cast(context, to: GraphQLContext.self)
6060
return try await parent.foo(context: context, info: info)
@@ -65,11 +65,11 @@ struct SchemaGeneratorTests {
6565
6666
let query = schema.typeMap["Query"] as? GraphQLObjectType
6767
let queryFields = try query?.fields() ?? [:]
68-
queryFields["foo"]?.resolve = { source, args, context, info in
68+
queryFields["foo"]?.resolve = { @Sendable source, args, context, info in
6969
let context = try cast(context, to: GraphQLContext.self)
7070
return try await Resolvers.Query.foo(context: context, info: info)
7171
}
72-
queryFields["bar"]?.resolve = { source, args, context, info in
72+
queryFields["bar"]?.resolve = { @Sendable source, args, context, info in
7373
let context = try cast(context, to: GraphQLContext.self)
7474
return try await Resolvers.Query.bar(context: context, info: info)
7575
}
@@ -103,7 +103,7 @@ struct SchemaGeneratorTests {
103103
104104
let node = schema.typeMap["Node"] as? GraphQLObjectType
105105
let nodeFields = try node?.fields() ?? [:]
106-
nodeFields["id"]?.resolve = { source, args, context, info in
106+
nodeFields["id"]?.resolve = { @Sendable source, args, context, info in
107107
let parent = try cast(source, to: (any GraphQLGenerated.Node).self)
108108
let context = try cast(context, to: GraphQLContext.self)
109109
return try await parent.id(context: context, info: info)
@@ -136,12 +136,12 @@ struct SchemaGeneratorTests {
136136
137137
let book = schema.typeMap["Book"] as? GraphQLObjectType
138138
let bookFields = try book?.fields() ?? [:]
139-
bookFields["title"]?.resolve = { source, args, context, info in
139+
bookFields["title"]?.resolve = { @Sendable source, args, context, info in
140140
let parent = try cast(source, to: (any GraphQLGenerated.Book).self)
141141
let context = try cast(context, to: GraphQLContext.self)
142142
return try await parent.title(context: context, info: info)
143143
}
144-
bookFields["author"]?.resolve = { source, args, context, info in
144+
bookFields["author"]?.resolve = { @Sendable source, args, context, info in
145145
let parent = try cast(source, to: (any GraphQLGenerated.Book).self)
146146
let context = try cast(context, to: GraphQLContext.self)
147147
return try await parent.author(context: context, info: info)
@@ -172,7 +172,7 @@ struct SchemaGeneratorTests {
172172
173173
let query = schema.typeMap["Query"] as? GraphQLObjectType
174174
let queryFields = try query?.fields() ?? [:]
175-
queryFields["user"]?.resolve = { source, args, context, info in
175+
queryFields["user"]?.resolve = { @Sendable source, args, context, info in
176176
let context = try cast(context, to: GraphQLContext.self)
177177
return try await Resolvers.Query.user(context: context, info: info)
178178
}
@@ -201,7 +201,7 @@ struct SchemaGeneratorTests {
201201
202202
let mutation = schema.typeMap["Mutation"] as? GraphQLObjectType
203203
let mutationFields = try mutation?.fields() ?? [:]
204-
mutationFields["createUser"]?.resolve = { source, args, context, info in
204+
mutationFields["createUser"]?.resolve = { @Sendable source, args, context, info in
205205
let context = try cast(context, to: GraphQLContext.self)
206206
return try await Resolvers.Mutation.createUser(context: context, info: info)
207207
}
@@ -230,10 +230,10 @@ struct SchemaGeneratorTests {
230230
231231
let subscription = schema.typeMap["Subscription"] as? GraphQLObjectType
232232
let subscriptionFields = try subscription?.fields() ?? [:]
233-
subscriptionFields["userUpdated"]?.resolve = { source, _, _, _ in
233+
subscriptionFields["userUpdated"]?.resolve = { @Sendable source, _, _, _ in
234234
return source
235235
}
236-
subscriptionFields["userUpdated"]?.subscribe = { source, args, context, info in
236+
subscriptionFields["userUpdated"]?.subscribe = { @Sendable source, args, context, info in
237237
let context = try cast(context, to: GraphQLContext.self)
238238
return try await Resolvers.Subscription.userUpdated(context: context, info: info)
239239
}
@@ -268,7 +268,7 @@ struct SchemaGeneratorTests {
268268
)
269269

270270
let expected = """
271-
queryFields["posts"]?.resolve = { source, args, context, info in
271+
queryFields["posts"]?.resolve = { @Sendable source, args, context, info in
272272
let parent = try cast(source, to: (any GraphQLGenerated.User).self)
273273
let filter = args["filter"] != .undefined ? try decoder.decode((String?).self, from: args["filter"]) : nil
274274
let scalar = try decoder.decode((GraphQLScalars.Scalar).self, from: args["scalar"])
@@ -299,7 +299,7 @@ struct SchemaGeneratorTests {
299299
)
300300

301301
let expected = """
302-
queryFields["user"]?.resolve = { source, args, context, info in
302+
queryFields["user"]?.resolve = { @Sendable source, args, context, info in
303303
let id = try decoder.decode((String).self, from: args["id"])
304304
let context = try cast(context, to: GraphQLContext.self)
305305
return try await Resolvers.Query.user(id: id, context: context, info: info)
@@ -325,10 +325,10 @@ struct SchemaGeneratorTests {
325325
)
326326

327327
let expected = """
328-
subscriptionFields["messageAdded"]?.resolve = { source, _, _, _ in
328+
subscriptionFields["messageAdded"]?.resolve = { @Sendable source, _, _, _ in
329329
return source
330330
}
331-
subscriptionFields["messageAdded"]?.subscribe = { source, args, context, info in
331+
subscriptionFields["messageAdded"]?.subscribe = { @Sendable source, args, context, info in
332332
let context = try cast(context, to: GraphQLContext.self)
333333
return try await Resolvers.Subscription.messageAdded(context: context, info: info)
334334
}

0 commit comments

Comments
 (0)