Skip to content

Commit

Permalink
Add order support for relation numeric aggs
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSisley committed Sep 15, 2022
1 parent 4f61926 commit 6f21897
Show file tree
Hide file tree
Showing 6 changed files with 480 additions and 3 deletions.
21 changes: 18 additions & 3 deletions query/graphql/mapper/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,9 @@ func resolveAggregates(
Index: index,
Name: target.hostExternalName,
},
Filter: convertedFilter,
Limit: target.limit,
Filter: convertedFilter,
Limit: target.limit,
OrderBy: toOrderBy(target.order, childMapping),
},
CollectionName: childCollectionName,
DocumentMapping: *childMapping,
Expand Down Expand Up @@ -1174,8 +1175,22 @@ func getAggregateSources(field *parser.Select) ([]*aggregateRequestTarget, error
},
},
}
}

case *ast.ObjectValue:
// For relations the order arg will be the complex order object as used by the host object
// for non-aggregate ordering

// We use the parser package parsing for convienience here
orderConditions, err := parser.ParseConditionsInOrder(orderArgValue)
if err != nil {
return nil, err
}

order = &parserTypes.OrderBy{
Conditions: orderConditions,
Statement: orderArgValue,
}
}
}

targets[i] = &aggregateRequestTarget{
Expand Down
4 changes: 4 additions & 0 deletions query/graphql/schema/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,10 @@ func (g *Generator) genNumericAggregateBaseArgInputs(obj *gql.Object) *gql.Input
Type: gql.Int,
Description: "The index from which to start aggregating items.",
},
parserTypes.OrderClause: &gql.InputObjectFieldConfig{
Type: g.manager.schema.TypeMap()[genTypeName(obj, "OrderArg")],
Description: "The order in which to aggregate items.",
},
}, nil
}

Expand Down
Loading

0 comments on commit 6f21897

Please sign in to comment.