diff --git a/query/graphql/mapper/mapper.go b/query/graphql/mapper/mapper.go index 7413daee4d..f1831d634b 100644 --- a/query/graphql/mapper/mapper.go +++ b/query/graphql/mapper/mapper.go @@ -798,27 +798,27 @@ func toOrderBy(source *parserTypes.OrderBy, mapping *core.DocumentMapping) *Orde } conditions := make([]OrderCondition, len(source.Conditions)) - for _, condition := range source.Conditions { + for conditionIndex, condition := range source.Conditions { fields := strings.Split(condition.Field, ".") fieldIndexes := make([]int, len(fields)) currentMapping := mapping - for i, field := range fields { + for fieldIndex, field := range fields { // If there are multiple properties of the same name we can just take the first as // we have no other reasonable way of identifying which property they mean if multiple // consumer specified requestables are available. Aggregate dependencies should not // impact this as they are added after selects. - fieldIndex := currentMapping.FirstIndexOfName(field) - fieldIndexes[i] = fieldIndex - if i != len(fields)-1 { + firstFieldIndex := currentMapping.FirstIndexOfName(field) + fieldIndexes[fieldIndex] = firstFieldIndex + if fieldIndex != len(fields)-1 { // no need to do this for the last (and will panic) - currentMapping = ¤tMapping.ChildMappings[fieldIndex] + currentMapping = ¤tMapping.ChildMappings[firstFieldIndex] } } - conditions = append(conditions, OrderCondition{ + conditions[conditionIndex] = OrderCondition{ FieldIndexes: fieldIndexes, Direction: SortDirection(condition.Direction), - }) + } } return &OrderBy{ diff --git a/query/graphql/mapper/targetable.go b/query/graphql/mapper/targetable.go index 3d0b679a22..0de68643e0 100644 --- a/query/graphql/mapper/targetable.go +++ b/query/graphql/mapper/targetable.go @@ -106,13 +106,6 @@ type OrderCondition struct { Direction SortDirection } -func (oc OrderCondition) IsEmpty() bool { - if oc.Direction == "" && len(oc.FieldIndexes) == 0 { - return true - } - return false -} - type OrderBy struct { Conditions []OrderCondition } diff --git a/query/graphql/planner/order.go b/query/graphql/planner/order.go index 9c9a278535..1fec3fd883 100644 --- a/query/graphql/planner/order.go +++ b/query/graphql/planner/order.go @@ -103,11 +103,6 @@ func (n *orderNode) Explain() (map[string]interface{}, error) { orderings := []map[string]interface{}{} for _, element := range n.ordering { - // Skip all empty elements. - if element.IsEmpty() { - continue - } - // Build the list containing the corresponding names of all the indexes. fieldNames := []string{} for _, fieldIndex := range element.FieldIndexes { diff --git a/query/graphql/planner/select.go b/query/graphql/planner/select.go index 90b0af0156..82bf62b879 100644 --- a/query/graphql/planner/select.go +++ b/query/graphql/planner/select.go @@ -417,7 +417,7 @@ func (p *Planner) Select(parsed *mapper.Select) (planNode, error) { docMapper: docMapper{&parsed.DocumentMapping}, } limit := parsed.Limit - order := parsed.OrderBy + orderBy := parsed.OrderBy groupBy := parsed.GroupBy aggregates, err := s.initSource() @@ -435,7 +435,7 @@ func (p *Planner) Select(parsed *mapper.Select) (planNode, error) { return nil, err } - orderPlan, err := p.OrderBy(parsed, order) + orderPlan, err := p.OrderBy(parsed, orderBy) if err != nil { return nil, err }