Default value for aggregate functions and sorting

Hi all, is there a way to do a default value for an aggregate function, e.g. 0 for a sum(children.points) or 0.


query {
  topic(func: eq(id, "1234")) {
    article(orderdesc: points, orderasc: createdAt) {
      points: sum(val(p)) # or 0
      votes {
        p as points

If article has no vote nodes than point is empty and sort doesn’t work. I’d like it to be 0 so sort can put it below others

Any tips?

if it is zero, it should be in the last of the result

Hi Jerry, my point is that it should be zero but it’s not. If there are no votes (no child nodes) than instead of zero, the points variable is “missing”. This causes the sort to order incorrectly.


if the point is missing, what’s the result’s order

Try adding a Kind


has (missing)

PS. But you should create an automatic process that adds zero to the new user. A simple registration mutation already with the added “zero” would solve this. Do not create blank fields where you need sorting.