@@ -38,6 +38,20 @@ class FieldExecutionStrategyTests: XCTestCase {
38
38
msg: " \( info. fieldName) : \( info. path. last as! String ) "
39
39
)
40
40
}
41
+ ) ,
42
+ " futureBang " : GraphQLField (
43
+ type: GraphQLString,
44
+ resolve: { ( _, _, _, eventLoopGroup, info: GraphQLResolveInfo ) in
45
+ let g = DispatchGroup ( )
46
+ g. enter ( )
47
+ DispatchQueue . global ( ) . asyncAfter ( wallDeadline: . now( ) + 0.1 ) {
48
+ g. leave ( )
49
+ }
50
+ g. wait ( )
51
+ return eventLoopGroup. next ( ) . newFailedFuture ( error: StrategyError . exampleError (
52
+ msg: " \( info. fieldName) : \( info. path. last as! String ) "
53
+ ) )
54
+ }
41
55
)
42
56
]
43
57
)
@@ -81,8 +95,24 @@ class FieldExecutionStrategyTests: XCTestCase {
81
95
]
82
96
]
83
97
]
98
+
99
+ let singleFailedFutureQuery = " { futureBang } "
100
+ let singleFailedFutureExpected : Map = [
101
+ " data " : [
102
+ " futureBang " : nil
103
+ ] ,
104
+ " errors " : [
105
+ [
106
+ " locations " : [
107
+ [ " column " : 3 , " line " : 1 ]
108
+ ] ,
109
+ " message " : " exampleError(msg: \" futureBang: futureBang \" ) " ,
110
+ " path " : [ " futureBang " ]
111
+ ]
112
+ ]
113
+ ]
84
114
85
- let multiThrowsQuery = " { a: bang b: bang c: bang d: bang e: bang f: bang g: bang h: bang i: bang j: bang } "
115
+ let multiThrowsQuery = " { a: bang b: bang c: bang d: bang e: bang f: bang g: bang h: bang i: bang j: futureBang } "
86
116
let multiThrowsExpectedData : Map = [
87
117
" a " : nil ,
88
118
" b " : nil ,
@@ -163,7 +193,7 @@ class FieldExecutionStrategyTests: XCTestCase {
163
193
" locations " : [
164
194
[ " column " : 75 , " line " : 1 ]
165
195
] ,
166
- " message " : " exampleError(msg: \" bang : j\" ) " ,
196
+ " message " : " exampleError(msg: \" futureBang : j\" ) " ,
167
197
" path " : [ " j " ]
168
198
] ,
169
199
]
@@ -210,6 +240,22 @@ class FieldExecutionStrategyTests: XCTestCase {
210
240
XCTAssertEqual ( result. value, singleThrowsExpected)
211
241
//XCTAssertEqualWithAccuracy(0.1, result.seconds, accuracy: 0.25)
212
242
}
243
+
244
+ func testSerialFieldExecutionStrategyWithSingleFieldFailedFuture( ) throws {
245
+ let eventLoopGroup = MultiThreadedEventLoopGroup ( numThreads: 1 )
246
+ defer {
247
+ XCTAssertNoThrow ( try eventLoopGroup. syncShutdownGracefully ( ) )
248
+ }
249
+
250
+ let result = try timing ( try graphql (
251
+ queryStrategy: SerialFieldExecutionStrategy ( ) ,
252
+ schema: schema,
253
+ request: singleFailedFutureQuery,
254
+ eventLoopGroup: eventLoopGroup
255
+ ) . wait ( ) )
256
+ XCTAssertEqual ( result. value, singleFailedFutureExpected)
257
+ //XCTAssertEqualWithAccuracy(0.1, result.seconds, accuracy: 0.25)
258
+ }
213
259
214
260
func testSerialFieldExecutionStrategyWithMultipleFields( ) throws {
215
261
let eventLoopGroup = MultiThreadedEventLoopGroup ( numThreads: 1 )
@@ -324,6 +370,7 @@ extension FieldExecutionStrategyTests {
324
370
return [
325
371
( " testSerialFieldExecutionStrategyWithSingleField " , testSerialFieldExecutionStrategyWithSingleField) ,
326
372
( " testSerialFieldExecutionStrategyWithSingleFieldError " , testSerialFieldExecutionStrategyWithSingleFieldError) ,
373
+ ( " testSerialFieldExecutionStrategyWithSingleFieldFailedFuture " , testSerialFieldExecutionStrategyWithSingleFieldFailedFuture) ,
327
374
( " testSerialFieldExecutionStrategyWithMultipleFields " , testSerialFieldExecutionStrategyWithMultipleFields) ,
328
375
( " testSerialFieldExecutionStrategyWithMultipleFieldErrors " , testSerialFieldExecutionStrategyWithMultipleFieldErrors) ,
329
376
( " testConcurrentDispatchFieldExecutionStrategyWithSingleField " , testConcurrentDispatchFieldExecutionStrategyWithSingleField) ,
0 commit comments