Skip to content

Commit cc18794

Browse files
committed
Cleaned up code structure a little bit.
1 parent 2c53a57 commit cc18794

File tree

1 file changed

+27
-29
lines changed

1 file changed

+27
-29
lines changed

executor.go

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -227,21 +227,6 @@ type executeFieldsParams struct {
227227
Path *responsePath
228228
}
229229

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-
245230
// Implements the "Evaluating selection sets" section of the spec for "write" mode.
246231
func executeFieldsSerially(p executeFieldsParams) *Result {
247232
if p.Source == nil {
@@ -260,28 +245,19 @@ func executeFieldsSerially(p executeFieldsParams) *Result {
260245
}
261246
finalResults[responseName] = resolved
262247
}
263-
dethunkWithBreadthFirstSearch(finalResults)
248+
dethunkWithBreadthFirstTraversal(finalResults)
264249

265250
return &Result{
266251
Data: finalResults,
267252
Errors: p.ExecutionContext.Errors,
268253
}
269254
}
270255

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-
280256
// Implements the "Evaluating selection sets" section of the spec for "read" mode.
281257
func executeFields(p executeFieldsParams) *Result {
282258
finalResults := executeSubFields(p)
283259

284-
dethunkWithBreadthFirstSearch(finalResults)
260+
dethunkWithBreadthFirstTraversal(finalResults)
285261

286262
return &Result{
287263
Data: finalResults,
@@ -310,8 +286,32 @@ func executeSubFields(p executeFieldsParams) map[string]interface{} {
310286
return finalResults
311287
}
312288

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
314305
// 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+
315315
func dethunkMap(m map[string]interface{}, dethunkQueue *dethunkQueue) {
316316
for k, v := range m {
317317
if f, ok := v.(func() interface{}); ok {
@@ -328,8 +328,6 @@ func dethunkMap(m map[string]interface{}, dethunkQueue *dethunkQueue) {
328328
}
329329
}
330330

331-
// dethunkList iterates through the list, calling any thunks in the list
332-
// and replacing each thunk with that thunk's return value.
333331
func dethunkList(list []interface{}, dethunkQueue *dethunkQueue) {
334332
for i, v := range list {
335333
if f, ok := v.(func() interface{}); ok {

0 commit comments

Comments
 (0)