@@ -227,21 +227,6 @@ type executeFieldsParams struct {
227
227
Path * responsePath
228
228
}
229
229
230
- // dethunkQueue is a structure that allows us to execute a classic breadth-first search.
231
- type dethunkQueue struct {
232
- DethunkFuncs []func ()
233
- }
234
-
235
- func (d * dethunkQueue ) push (f func ()) {
236
- d .DethunkFuncs = append (d .DethunkFuncs , f )
237
- }
238
-
239
- func (d * dethunkQueue ) shift () func () {
240
- f := d .DethunkFuncs [0 ]
241
- d .DethunkFuncs = d .DethunkFuncs [1 :]
242
- return f
243
- }
244
-
245
230
// Implements the "Evaluating selection sets" section of the spec for "write" mode.
246
231
func executeFieldsSerially (p executeFieldsParams ) * Result {
247
232
if p .Source == nil {
@@ -260,28 +245,19 @@ func executeFieldsSerially(p executeFieldsParams) *Result {
260
245
}
261
246
finalResults [responseName ] = resolved
262
247
}
263
- dethunkWithBreadthFirstSearch (finalResults )
248
+ dethunkWithBreadthFirstTraversal (finalResults )
264
249
265
250
return & Result {
266
251
Data : finalResults ,
267
252
Errors : p .ExecutionContext .Errors ,
268
253
}
269
254
}
270
255
271
- func dethunkWithBreadthFirstSearch (finalResults map [string ]interface {}) {
272
- dethunkQueue := & dethunkQueue {DethunkFuncs : []func (){}}
273
- dethunkMap (finalResults , dethunkQueue )
274
- for len (dethunkQueue .DethunkFuncs ) > 0 {
275
- f := dethunkQueue .shift ()
276
- f ()
277
- }
278
- }
279
-
280
256
// Implements the "Evaluating selection sets" section of the spec for "read" mode.
281
257
func executeFields (p executeFieldsParams ) * Result {
282
258
finalResults := executeSubFields (p )
283
259
284
- dethunkWithBreadthFirstSearch (finalResults )
260
+ dethunkWithBreadthFirstTraversal (finalResults )
285
261
286
262
return & Result {
287
263
Data : finalResults ,
@@ -310,8 +286,32 @@ func executeSubFields(p executeFieldsParams) map[string]interface{} {
310
286
return finalResults
311
287
}
312
288
313
- // dethunkMap performs a breadth-first descent of the map, calling any thunks
289
+ // dethunkQueue is a structure that allows us to execute a classic breadth-first traversal.
290
+ type dethunkQueue struct {
291
+ DethunkFuncs []func ()
292
+ }
293
+
294
+ func (d * dethunkQueue ) push (f func ()) {
295
+ d .DethunkFuncs = append (d .DethunkFuncs , f )
296
+ }
297
+
298
+ func (d * dethunkQueue ) shift () func () {
299
+ f := d .DethunkFuncs [0 ]
300
+ d .DethunkFuncs = d .DethunkFuncs [1 :]
301
+ return f
302
+ }
303
+
304
+ // dethunkWithBreadthFirstTraversal performs a breadth-first descent of the map, calling any thunks
314
305
// in the map values and replacing each thunk with that thunk's return value.
306
+ func dethunkWithBreadthFirstTraversal (finalResults map [string ]interface {}) {
307
+ dethunkQueue := & dethunkQueue {DethunkFuncs : []func (){}}
308
+ dethunkMap (finalResults , dethunkQueue )
309
+ for len (dethunkQueue .DethunkFuncs ) > 0 {
310
+ f := dethunkQueue .shift ()
311
+ f ()
312
+ }
313
+ }
314
+
315
315
func dethunkMap (m map [string ]interface {}, dethunkQueue * dethunkQueue ) {
316
316
for k , v := range m {
317
317
if f , ok := v .(func () interface {}); ok {
@@ -328,8 +328,6 @@ func dethunkMap(m map[string]interface{}, dethunkQueue *dethunkQueue) {
328
328
}
329
329
}
330
330
331
- // dethunkList iterates through the list, calling any thunks in the list
332
- // and replacing each thunk with that thunk's return value.
333
331
func dethunkList (list []interface {}, dethunkQueue * dethunkQueue ) {
334
332
for i , v := range list {
335
333
if f , ok := v .(func () interface {}); ok {
0 commit comments