@@ -99,7 +99,7 @@ public protocol FieldExecutionStrategy {
99
99
sourceValue: Any ,
100
100
path: IndexPath ,
101
101
fields: [ String : [ Field ] ]
102
- ) throws -> EventLoopFuture < [ String : Any ] >
102
+ ) throws -> Future < [ String : Any ] >
103
103
}
104
104
105
105
public protocol MutationFieldExecutionStrategy : FieldExecutionStrategy { }
@@ -119,8 +119,8 @@ public struct SerialFieldExecutionStrategy: QueryFieldExecutionStrategy, Mutatio
119
119
sourceValue: Any ,
120
120
path: IndexPath ,
121
121
fields: [ String : [ Field ] ]
122
- ) throws -> EventLoopFuture < [ String : Any ] > {
123
- var results = [ String : EventLoopFuture < Any > ] ( )
122
+ ) throws -> Future < [ String : Any ] > {
123
+ var results = [ String : Future < Any > ] ( )
124
124
125
125
try fields. forEach { field in
126
126
let fieldASTs = field. value
@@ -154,7 +154,10 @@ public struct ConcurrentDispatchFieldExecutionStrategy: QueryFieldExecutionStrat
154
154
self . dispatchQueue = dispatchQueue
155
155
}
156
156
157
- public init ( queueLabel: String = " GraphQL field execution " , queueQoS: DispatchQoS = . userInitiated) {
157
+ public init (
158
+ queueLabel: String = " GraphQL field execution " ,
159
+ queueQoS: DispatchQoS = . userInitiated
160
+ ) {
158
161
self . dispatchQueue = DispatchQueue (
159
162
label: queueLabel,
160
163
qos: queueQoS,
@@ -168,14 +171,14 @@ public struct ConcurrentDispatchFieldExecutionStrategy: QueryFieldExecutionStrat
168
171
sourceValue: Any ,
169
172
path: IndexPath ,
170
173
fields: [ String : [ Field ] ]
171
- ) throws -> EventLoopFuture < [ String : Any ] > {
172
-
174
+ ) throws -> Future < [ String : Any ] > {
173
175
let resultsQueue = DispatchQueue (
174
176
label: " \( dispatchQueue. label) results " ,
175
177
qos: dispatchQueue. qos
176
178
)
179
+
177
180
let group = DispatchGroup ( )
178
- var results : [ String : EventLoopFuture < Any > ] = [ : ]
181
+ var results : [ String : Future < Any > ] = [ : ]
179
182
var err : Error ? = nil
180
183
181
184
fields. forEach { field in
@@ -204,7 +207,9 @@ public struct ConcurrentDispatchFieldExecutionStrategy: QueryFieldExecutionStrat
204
207
}
205
208
}
206
209
}
210
+
207
211
group. wait ( )
212
+
208
213
if let error = err {
209
214
throw error
210
215
}
@@ -232,7 +237,7 @@ func execute(
232
237
eventLoopGroup: EventLoopGroup ,
233
238
variableValues: [ String : Map ] = [ : ] ,
234
239
operationName: String ? = nil
235
- ) -> EventLoopFuture < GraphQLResult > {
240
+ ) -> Future < GraphQLResult > {
236
241
let executeStarted = instrumentation. now
237
242
let buildContext : ExecutionContext
238
243
@@ -410,7 +415,7 @@ func executeOperation(
410
415
exeContext: ExecutionContext ,
411
416
operation: OperationDefinition ,
412
417
rootValue: Any
413
- ) throws -> EventLoopFuture < [ String : Any ] > {
418
+ ) throws -> Future < [ String : Any ] > {
414
419
let type = try getOperationRootType ( schema: exeContext. schema, operation: operation)
415
420
var inputFields : [ String : [ Field ] ] = [ : ]
416
421
var visitedFragmentNames : [ String : Bool ] = [ : ]
@@ -655,7 +660,7 @@ public func resolveField(
655
660
source: Any ,
656
661
fieldASTs: [ Field ] ,
657
662
path: IndexPath
658
- ) throws -> EventLoopFuture < Any ? > {
663
+ ) throws -> Future < Any ? > {
659
664
let fieldAST = fieldASTs [ 0 ]
660
665
let fieldName = fieldAST. name. value
661
666
@@ -697,7 +702,7 @@ public func resolveField(
697
702
variableValues: exeContext. variableValues
698
703
)
699
704
700
- let resolveFieldStarted = exeContext. instrumentation. now
705
+ // let resolveFieldStarted = exeContext.instrumentation.now
701
706
702
707
// Get the resolve func, regardless of if its result is normal
703
708
// or abrupt (error).
@@ -710,17 +715,17 @@ public func resolveField(
710
715
info: info
711
716
)
712
717
713
- exeContext. instrumentation. fieldResolution (
714
- processId: processId ( ) ,
715
- threadId: threadId ( ) ,
716
- started: resolveFieldStarted,
717
- finished: exeContext. instrumentation. now,
718
- source: source,
719
- args: args,
720
- eventLoopGroup: exeContext. eventLoopGroup,
721
- info: info,
722
- result: result
723
- )
718
+ // exeContext.instrumentation.fieldResolution(
719
+ // processId: processId(),
720
+ // threadId: threadId(),
721
+ // started: resolveFieldStarted,
722
+ // finished: exeContext.instrumentation.now,
723
+ // source: source,
724
+ // args: args,
725
+ // eventLoopGroup: exeContext.eventLoopGroup,
726
+ // info: info,
727
+ // result: result
728
+ // )
724
729
725
730
return try completeValueCatchingError (
726
731
exeContext: exeContext,
@@ -732,11 +737,6 @@ public func resolveField(
732
737
)
733
738
}
734
739
735
- public enum ResultOrError < T, E> {
736
- case result( T )
737
- case error( E )
738
- }
739
-
740
740
// Isolates the "ReturnOrAbrupt" behavior to not de-opt the `resolveField`
741
741
// function. Returns the result of `resolve` or the abrupt-return Error object.
742
742
func resolveOrError(
@@ -746,11 +746,12 @@ func resolveOrError(
746
746
context: Any ,
747
747
eventLoopGroup: EventLoopGroup ,
748
748
info: GraphQLResolveInfo
749
- ) -> ResultOrError < EventLoopFuture < Any ? > , Error > {
749
+ ) -> Result < Future < Any ? > , Error > {
750
750
do {
751
- return try . result( resolve ( source, args, context, eventLoopGroup, info) )
751
+ let result = try resolve ( source, args, context, eventLoopGroup, info)
752
+ return . success( result)
752
753
} catch {
753
- return . error ( error)
754
+ return . failure ( error)
754
755
}
755
756
}
756
757
@@ -762,8 +763,8 @@ func completeValueCatchingError(
762
763
fieldASTs: [ Field ] ,
763
764
info: GraphQLResolveInfo ,
764
765
path: IndexPath ,
765
- result: ResultOrError < EventLoopFuture < Any ? > , Error >
766
- ) throws -> EventLoopFuture < Any ? > {
766
+ result: Result < Future < Any ? > , Error >
767
+ ) throws -> Future < Any ? > {
767
768
// If the field type is non-nullable, then it is resolved without any
768
769
// protection from errors, however it still properly locates the error.
769
770
if let returnType = returnType as? GraphQLNonNull {
@@ -787,13 +788,13 @@ func completeValueCatchingError(
787
788
info: info,
788
789
path: path,
789
790
result: result
790
- ) . mapIfError { error -> Any ? in
791
- guard let error = error as? GraphQLError else {
792
- fatalError ( )
793
- }
794
- exeContext. append ( error: error)
795
- return nil
791
+ ) . mapIfError { error -> Any ? in
792
+ guard let error = error as? GraphQLError else {
793
+ fatalError ( )
796
794
}
795
+ exeContext. append ( error: error)
796
+ return nil
797
+ }
797
798
798
799
return completed
799
800
} catch let error as GraphQLError {
@@ -814,8 +815,8 @@ func completeValueWithLocatedError(
814
815
fieldASTs: [ Field ] ,
815
816
info: GraphQLResolveInfo ,
816
817
path: IndexPath ,
817
- result: ResultOrError < EventLoopFuture < Any ? > , Error >
818
- ) throws -> EventLoopFuture < Any ? > {
818
+ result: Result < Future < Any ? > , Error >
819
+ ) throws -> Future < Any ? > {
819
820
do {
820
821
let completed = try completeValue (
821
822
exeContext: exeContext,
@@ -864,12 +865,12 @@ func completeValue(
864
865
fieldASTs: [ Field ] ,
865
866
info: GraphQLResolveInfo ,
866
867
path: IndexPath ,
867
- result: ResultOrError < EventLoopFuture < Any ? > , Error >
868
- ) throws -> EventLoopFuture < Any ? > {
868
+ result: Result < Future < Any ? > , Error >
869
+ ) throws -> Future < Any ? > {
869
870
switch result {
870
- case . error ( let error) :
871
+ case let . failure ( error) :
871
872
throw error
872
- case . result ( let result) :
873
+ case let . success ( result) :
873
874
// If field type is NonNull, complete for inner type, and throw field error
874
875
// if result is nullish.
875
876
if let returnType = returnType as? GraphQLNonNull {
@@ -879,7 +880,7 @@ func completeValue(
879
880
fieldASTs: fieldASTs,
880
881
info: info,
881
882
path: path,
882
- result: . result ( result)
883
+ result: . success ( result)
883
884
) . thenThrowing { value -> Any ? in
884
885
guard let value = value else {
885
886
throw GraphQLError ( message: " Cannot return null for non-nullable field \( info. parentType. name) . \( info. fieldName) . " )
@@ -889,7 +890,7 @@ func completeValue(
889
890
}
890
891
}
891
892
892
- return result. flatMap ( to: Any ? . self) { result -> EventLoopFuture < Any ? > in
893
+ return result. flatMap ( to: Any ? . self) { result -> Future < Any ? > in
893
894
// If result value is null-ish (nil or .null) then return .null.
894
895
guard let result = result, let r = unwrap ( result) else {
895
896
return exeContext. eventLoopGroup. next ( ) . newSucceededFuture ( result: nil )
@@ -955,7 +956,7 @@ func completeListValue(
955
956
info: GraphQLResolveInfo ,
956
957
path: IndexPath ,
957
958
result: Any
958
- ) throws -> EventLoopFuture < [ Any ? ] > {
959
+ ) throws -> Future < [ Any ? ] > {
959
960
guard let result = result as? [ Any ? ] else {
960
961
throw GraphQLError (
961
962
message:
@@ -965,21 +966,21 @@ func completeListValue(
965
966
}
966
967
967
968
let itemType = returnType. ofType
968
- var completedResults : [ EventLoopFuture < Any ? > ] = [ ]
969
+ var completedResults : [ Future < Any ? > ] = [ ]
969
970
970
971
for (index, item) in result. enumerated ( ) {
971
972
// No need to modify the info object containing the path,
972
973
// since from here on it is not ever accessed by resolver funcs.
973
974
let fieldPath = path. appending ( index)
974
- let futureItem = item as? EventLoopFuture < Any ? > ?? exeContext. eventLoopGroup. next ( ) . newSucceededFuture ( result: item)
975
+ let futureItem = item as? Future < Any ? > ?? exeContext. eventLoopGroup. next ( ) . newSucceededFuture ( result: item)
975
976
976
977
let completedItem = try completeValueCatchingError (
977
978
exeContext: exeContext,
978
979
returnType: itemType,
979
980
fieldASTs: fieldASTs,
980
981
info: info,
981
982
path: fieldPath,
982
- result: . result ( futureItem)
983
+ result: . success ( futureItem)
983
984
)
984
985
985
986
completedResults. append ( completedItem)
@@ -1022,7 +1023,7 @@ func completeAbstractValue(
1022
1023
info: GraphQLResolveInfo ,
1023
1024
path: IndexPath ,
1024
1025
result: Any
1025
- ) throws -> EventLoopFuture < Any ? > {
1026
+ ) throws -> Future < Any ? > {
1026
1027
var resolveRes = try returnType. resolveType ? ( result, exeContext. eventLoopGroup, info) . typeResolveResult
1027
1028
1028
1029
resolveRes = try resolveRes ?? defaultResolveType (
@@ -1088,7 +1089,7 @@ func completeObjectValue(
1088
1089
info: GraphQLResolveInfo ,
1089
1090
path: IndexPath ,
1090
1091
result: Any
1091
- ) throws -> EventLoopFuture < Any ? > {
1092
+ ) throws -> Future < Any ? > {
1092
1093
// If there is an isTypeOf predicate func, call it with the
1093
1094
// current result. If isTypeOf returns false, then raise an error rather
1094
1095
// than continuing execution.
@@ -1122,7 +1123,7 @@ func completeObjectValue(
1122
1123
sourceValue: result,
1123
1124
path: path,
1124
1125
fields: subFieldASTs
1125
- ) . map { $0 }
1126
+ ) . map { $0 }
1126
1127
}
1127
1128
1128
1129
/**
@@ -1156,7 +1157,7 @@ func defaultResolve(
1156
1157
context: Any ,
1157
1158
eventLoopGroup: EventLoopGroup ,
1158
1159
info: GraphQLResolveInfo
1159
- ) -> EventLoopFuture < Any ? > {
1160
+ ) -> Future < Any ? > {
1160
1161
#warning("Why not mark function as throwing?")
1161
1162
1162
1163
guard let source = unwrap ( source) else {
0 commit comments