v0.25.0 #1034
doug-martin
started this conversation in
Releases
v0.25.0
#1034
Replies: 1 comment
-
|
Super nice thanks !! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Aggregate Queries Return Arrays
In versions prior to
v0.25.0aggregate queries returned a single response with just the aggregated values. Inv0.25.0we have introduced a newgroupByoption that requires aggregates to return arrays.When using aggregates without the groupBy the response will always contain a single record with your aggregated
values. If you specify a
groupByyou will get a response with a distinct group and the corresponding aggregatedvalues.
Given the following query
{ todoItemAggregate { count { id } sum { id } avg { id } min { id title created } max { id title created } } }Old
The old response would look like
{ "data": { "todoItemAggregate": { "count": { "id": 5 }, "sum": { "id": 15 }, "avg": { "id": 3 }, "min": { "id": "1", "title": "Add Todo Item Resolver", "created": "2021-03-29T06:51:26.061Z" }, "max": { "id": "5", "title": "How to create item With Sub Tasks", "created": "2021-03-29T06:51:26.061Z" } } } }New
The new response will look like
{ "data": { "todoItemAggregate": [ { "count": { "id": 5 }, "sum": { "id": 15 }, "avg": { "id": 3 }, "min": { "id": "1", "title": "Add Todo Item Resolver", "created": "2021-03-29T06:51:26.061Z" }, "max": { "id": "5", "title": "How to create item With Sub Tasks", "created": "2021-03-29T06:51:26.061Z" } } ] } }New Aggregate GroupBy
The new response format really shines when using the
groupByqueryGiven the following aggregate grouping on
completed{ todoItemAggregate { groupBy { completed } count { id } sum { id } avg { id } min { id title created } max { id title created } } }You'll get the following response with record for each distinct group
{ "data": { "todoItemAggregate": [ { "groupBy": { "completed": false }, "count": { "id": 4 }, "sum": { "id": 14 }, "avg": { "id": 3.5 }, "min": { "id": "2", "title": "Add Todo Item Resolver", "created": "2021-03-29T06:51:26.061Z" }, "max": { "id": "5", "title": "How to create item With Sub Tasks", "created": "2021-03-29T06:51:26.061Z" } }, { "groupBy": { "completed": true }, "count": { "id": 1 }, "sum": { "id": 1 }, "avg": { "id": 1 }, "min": { "id": "1", "title": "Create Nest App", "created": "2021-03-29T06:51:26.061Z" }, "max": { "id": "1", "title": "Create Nest App", "created": "2021-03-29T06:51:26.061Z" } } ] } }Beta Was this translation helpful? Give feedback.
All reactions