@@ -27,14 +27,14 @@ import OrderedCollections
27
27
* Namely, schema of the type system that is currently executing,
28
28
* and the fragments defined in the query document
29
29
*/
30
- public final class ExecutionContext {
30
+ public final class ExecutionContext : @ unchecked Sendable {
31
31
let queryStrategy : QueryFieldExecutionStrategy
32
32
let mutationStrategy : MutationFieldExecutionStrategy
33
33
let subscriptionStrategy : SubscriptionFieldExecutionStrategy
34
34
public let schema : GraphQLSchema
35
35
public let fragments : [ String : FragmentDefinition ]
36
- public let rootValue : Any
37
- public let context : Any
36
+ public let rootValue : any Sendable
37
+ public let context : any Sendable
38
38
public let operation : OperationDefinition
39
39
public let variableValues : [ String : Map ]
40
40
@@ -55,8 +55,8 @@ public final class ExecutionContext {
55
55
subscriptionStrategy: SubscriptionFieldExecutionStrategy ,
56
56
schema: GraphQLSchema ,
57
57
fragments: [ String : FragmentDefinition ] ,
58
- rootValue: Any ,
59
- context: Any ,
58
+ rootValue: any Sendable ,
59
+ context: any Sendable ,
60
60
operation: OperationDefinition ,
61
61
variableValues: [ String : Map ] ,
62
62
errors: [ GraphQLError ]
@@ -86,10 +86,10 @@ public protocol FieldExecutionStrategy: Sendable {
86
86
func executeFields(
87
87
exeContext: ExecutionContext ,
88
88
parentType: GraphQLObjectType ,
89
- sourceValue: Any ,
89
+ sourceValue: any Sendable ,
90
90
path: IndexPath ,
91
91
fields: OrderedDictionary < String , [ Field ] >
92
- ) async throws -> OrderedDictionary < String , Any >
92
+ ) async throws -> OrderedDictionary < String , any Sendable >
93
93
}
94
94
95
95
public protocol MutationFieldExecutionStrategy : FieldExecutionStrategy { }
@@ -107,11 +107,11 @@ public struct SerialFieldExecutionStrategy: QueryFieldExecutionStrategy,
107
107
public func executeFields(
108
108
exeContext: ExecutionContext ,
109
109
parentType: GraphQLObjectType ,
110
- sourceValue: Any ,
110
+ sourceValue: any Sendable ,
111
111
path: IndexPath ,
112
112
fields: OrderedDictionary < String , [ Field ] >
113
- ) async throws -> OrderedDictionary < String , Any > {
114
- var results = OrderedDictionary < String , Any > ( )
113
+ ) async throws -> OrderedDictionary < String , any Sendable > {
114
+ var results = OrderedDictionary < String , any Sendable > ( )
115
115
for field in fields {
116
116
let fieldASTs = field. value
117
117
let fieldPath = path. appending ( field. key)
@@ -138,13 +138,14 @@ public struct ConcurrentFieldExecutionStrategy: QueryFieldExecutionStrategy,
138
138
public func executeFields(
139
139
exeContext: ExecutionContext ,
140
140
parentType: GraphQLObjectType ,
141
- sourceValue: Any ,
141
+ sourceValue: any Sendable ,
142
142
path: IndexPath ,
143
143
fields: OrderedDictionary < String , [ Field ] >
144
- ) async throws -> OrderedDictionary < String , Any > {
145
- return try await withThrowingTaskGroup ( of: ( String, Any ? ) . self) { group in
144
+ ) async throws -> OrderedDictionary < String , any Sendable > {
145
+ return try await withThrowingTaskGroup ( of: ( String, ( any Sendable ) ? ) . self) { group in
146
146
// preserve field order by assigning to null and filtering later
147
- var results : OrderedDictionary < String , Any ? > = fields. mapValues { _ -> Any ? in nil }
147
+ var results : OrderedDictionary < String , ( any Sendable ) ? > = fields
148
+ . mapValues { _ -> Any ? in nil }
148
149
for field in fields {
149
150
group. addTask {
150
151
let fieldASTs = field. value
@@ -179,8 +180,8 @@ func execute(
179
180
subscriptionStrategy: SubscriptionFieldExecutionStrategy ,
180
181
schema: GraphQLSchema ,
181
182
documentAST: Document ,
182
- rootValue: Any ,
183
- context: Any ,
183
+ rootValue: any Sendable ,
184
+ context: any Sendable ,
184
185
variableValues: [ String : Map ] = [ : ] ,
185
186
operationName: String ? = nil
186
187
) async throws -> GraphQLResult {
@@ -246,8 +247,8 @@ func buildExecutionContext(
246
247
subscriptionStrategy: SubscriptionFieldExecutionStrategy ,
247
248
schema: GraphQLSchema ,
248
249
documentAST: Document ,
249
- rootValue: Any ,
250
- context: Any ,
250
+ rootValue: any Sendable ,
251
+ context: any Sendable ,
251
252
rawVariableValues: [ String : Map ] ,
252
253
operationName: String ?
253
254
) throws -> ExecutionContext {
@@ -313,8 +314,8 @@ func buildExecutionContext(
313
314
func executeOperation(
314
315
exeContext: ExecutionContext ,
315
316
operation: OperationDefinition ,
316
- rootValue: Any
317
- ) async throws -> OrderedDictionary < String , Any > {
317
+ rootValue: any Sendable
318
+ ) async throws -> OrderedDictionary < String , any Sendable > {
318
319
let type = try getOperationRootType ( schema: exeContext. schema, operation: operation)
319
320
var inputFields : OrderedDictionary < String , [ Field ] > = [ : ]
320
321
var visitedFragmentNames : [ String : Bool ] = [ : ]
@@ -574,10 +575,10 @@ func getFieldEntryKey(node: Field) -> String {
574
575
public func resolveField(
575
576
exeContext: ExecutionContext ,
576
577
parentType: GraphQLObjectType ,
577
- source: Any ,
578
+ source: any Sendable ,
578
579
fieldASTs: [ Field ] ,
579
580
path: IndexPath
580
- ) async throws -> Any ? {
581
+ ) async throws -> ( any Sendable ) ? {
581
582
let fieldAST = fieldASTs [ 0 ]
582
583
let fieldName = fieldAST. name. value
583
584
@@ -643,11 +644,11 @@ public func resolveField(
643
644
// function. Returns the result of `resolve` or the abrupt-return Error object.
644
645
func resolveOrError(
645
646
resolve: GraphQLFieldResolve ,
646
- source: Any ,
647
+ source: any Sendable ,
647
648
args: Map ,
648
- context: Any ,
649
+ context: any Sendable ,
649
650
info: GraphQLResolveInfo
650
- ) async -> Result < Any ? , Error > {
651
+ ) async -> Result < ( any Sendable ) ? , Error > {
651
652
do {
652
653
let result = try await resolve ( source, args, context, info)
653
654
return . success( result)
@@ -664,8 +665,8 @@ func completeValueCatchingError(
664
665
fieldASTs: [ Field ] ,
665
666
info: GraphQLResolveInfo ,
666
667
path: IndexPath ,
667
- result: Result < Any ? , Error >
668
- ) async throws -> Any ? {
668
+ result: Result < ( any Sendable ) ? , Error >
669
+ ) async throws -> ( any Sendable ) ? {
669
670
// If the field type is non-nullable, then it is resolved without any
670
671
// protection from errors, however it still properly locates the error.
671
672
if let returnType = returnType as? GraphQLNonNull {
@@ -708,8 +709,8 @@ func completeValueWithLocatedError(
708
709
fieldASTs: [ Field ] ,
709
710
info: GraphQLResolveInfo ,
710
711
path: IndexPath ,
711
- result: Result < Any ? , Error >
712
- ) async throws -> Any ? {
712
+ result: Result < ( any Sendable ) ? , Error >
713
+ ) async throws -> ( any Sendable ) ? {
713
714
do {
714
715
return try await completeValue (
715
716
exeContext: exeContext,
@@ -755,8 +756,8 @@ func completeValue(
755
756
fieldASTs: [ Field ] ,
756
757
info: GraphQLResolveInfo ,
757
758
path: IndexPath ,
758
- result: Result < Any ? , Error >
759
- ) async throws -> Any ? {
759
+ result: Result < ( any Sendable ) ? , Error >
760
+ ) async throws -> ( any Sendable ) ? {
760
761
switch result {
761
762
case let . failure( error) :
762
763
throw error
@@ -846,9 +847,9 @@ func completeListValue(
846
847
fieldASTs: [ Field ] ,
847
848
info: GraphQLResolveInfo ,
848
849
path: IndexPath ,
849
- result: Any
850
- ) async throws -> [ Any ? ] {
851
- guard let result = result as? [ Any ? ] else {
850
+ result: any Sendable
851
+ ) async throws -> [ ( any Sendable ) ? ] {
852
+ guard let result = result as? [ ( any Sendable ) ? ] else {
852
853
throw GraphQLError (
853
854
message:
854
855
" Expected array, but did not find one for field " +
@@ -858,9 +859,9 @@ func completeListValue(
858
859
859
860
let itemType = returnType. ofType
860
861
861
- return try await withThrowingTaskGroup ( of: ( Int, Any ? ) . self) { group in
862
+ return try await withThrowingTaskGroup ( of: ( Int, ( any Sendable ) ? ) . self) { group in
862
863
// To preserve order, match size to result, and filter out nils at the end.
863
- var results : [ Any ? ] = result. map { _ in nil }
864
+ var results : [ ( any Sendable ) ? ] = result. map { _ in nil }
864
865
for (index, item) in result. enumerated ( ) {
865
866
group. addTask {
866
867
// No need to modify the info object containing the path,
@@ -889,7 +890,7 @@ func completeListValue(
889
890
* Complete a Scalar or Enum by serializing to a valid value, returning
890
891
* .null if serialization is not possible.
891
892
*/
892
- func completeLeafValue( returnType: GraphQLLeafType , result: Any ? ) throws -> Map {
893
+ func completeLeafValue( returnType: GraphQLLeafType , result: ( any Sendable ) ? ) throws -> Map {
893
894
guard let result = result else {
894
895
return . null
895
896
}
@@ -910,8 +911,8 @@ func completeAbstractValue(
910
911
fieldASTs: [ Field ] ,
911
912
info: GraphQLResolveInfo ,
912
913
path: IndexPath ,
913
- result: Any
914
- ) async throws -> Any ? {
914
+ result: any Sendable
915
+ ) async throws -> ( any Sendable ) ? {
915
916
var resolveRes = try returnType. resolveType ? ( result, info)
916
917
. typeResolveResult
917
918
@@ -976,8 +977,8 @@ func completeObjectValue(
976
977
fieldASTs: [ Field ] ,
977
978
info: GraphQLResolveInfo ,
978
979
path: IndexPath ,
979
- result: Any
980
- ) async throws -> Any ? {
980
+ result: any Sendable
981
+ ) async throws -> ( any Sendable ) ? {
981
982
// If there is an isTypeOf predicate func, call it with the
982
983
// current result. If isTypeOf returns false, then raise an error rather
983
984
// than continuing execution.
@@ -1023,7 +1024,7 @@ func completeObjectValue(
1023
1024
* isTypeOf for the object being coerced, returning the first type that matches.
1024
1025
*/
1025
1026
func defaultResolveType(
1026
- value: Any ,
1027
+ value: any Sendable ,
1027
1028
info: GraphQLResolveInfo ,
1028
1029
abstractType: GraphQLAbstractType
1029
1030
) throws -> TypeResolveResult ? {
@@ -1045,11 +1046,11 @@ func defaultResolveType(
1045
1046
* and returns it as the result.
1046
1047
*/
1047
1048
func defaultResolve(
1048
- source: Any ,
1049
+ source: any Sendable ,
1049
1050
args _: Map ,
1050
- context _: Any ,
1051
+ context _: any Sendable ,
1051
1052
info: GraphQLResolveInfo
1052
- ) async throws -> Any ? {
1053
+ ) async throws -> ( any Sendable ) ? {
1053
1054
guard let source = unwrap ( source) else {
1054
1055
return nil
1055
1056
}
@@ -1058,11 +1059,11 @@ func defaultResolve(
1058
1059
let value = subscriptable [ info. fieldName]
1059
1060
return value
1060
1061
}
1061
- if let subscriptable = source as? [ String : Any ] {
1062
+ if let subscriptable = source as? [ String : any Sendable ] {
1062
1063
let value = subscriptable [ info. fieldName]
1063
1064
return value
1064
1065
}
1065
- if let subscriptable = source as? OrderedDictionary < String , Any > {
1066
+ if let subscriptable = source as? OrderedDictionary < String , any Sendable > {
1066
1067
let value = subscriptable [ info. fieldName]
1067
1068
return value
1068
1069
}
0 commit comments