Skip to content

Commit

Permalink
removing ordered fields code to keep PRs separate
Browse files Browse the repository at this point in the history
  • Loading branch information
branden-blackline committed Jul 14, 2019
1 parent bd370d7 commit e96c7c7
Showing 1 changed file with 1 addition and 40 deletions.
41 changes: 1 addition & 40 deletions executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"reflect"
"sort"
"strings"

"github.com/graphql-go/graphql/gqlerrors"
Expand Down Expand Up @@ -255,9 +254,7 @@ func executeFieldsSerially(p executeFieldsParams) *Result {
}

finalResults := make(map[string]interface{}, len(p.Fields))
for _, orderedField := range orderedFields(p.Fields) {
responseName := orderedField.responseName
fieldASTs := orderedField.fieldASTs
for responseName, fieldASTs := range p.Fields {
fieldPath := p.Path.WithKey(responseName)
resolved, state := resolveField(p.ExecutionContext, p.ParentType, p.Source, fieldASTs, fieldPath)
if state.hasNoFieldDefs {
Expand Down Expand Up @@ -1041,39 +1038,3 @@ func getFieldDef(schema Schema, parentType *Object, fieldName string) *FieldDefi
}
return parentType.Fields()[fieldName]
}

// contains field information that will be placed in an ordered slice
type orderedField struct {
responseName string
fieldASTs []*ast.Field
}

// orders fields from a fields map by location in the source
func orderedFields(fields map[string][]*ast.Field) []*orderedField {
orderedFields := []*orderedField{}
fieldMap := map[int]*orderedField{}
startLocs := []int{}

for responseName, fieldASTs := range fields {
// find the lowest location in the current fieldASTs
lowest := -1
for _, fieldAST := range fieldASTs {
loc := fieldAST.GetLoc().Start
if lowest == -1 || loc < lowest {
lowest = loc
}
}
startLocs = append(startLocs, lowest)
fieldMap[lowest] = &orderedField{
responseName: responseName,
fieldASTs: fieldASTs,
}
}

sort.Ints(startLocs)
for _, startLoc := range startLocs {
orderedFields = append(orderedFields, fieldMap[startLoc])
}

return orderedFields
}

0 comments on commit e96c7c7

Please sign in to comment.