Adding sorting to DQL query with @groupby reduces results unexpectedly

My Schema:

type Stems  {
	id: ID! 
	link: String! 
	image: String! 
	name: String! @search(by:[fulltext]) 
	length: Int @search 
	rise: Int @search 
	clampDiameter: Float @search 
	steererDiameter: String @search(by:[hash]) 
	color: String @search(by:[hash]) 
	material: String! @search(by:[hash]) 
	price: Float! @search 
	weight: Int @search 
	brand: String! @search(by:[hash]) 
}

This query:

{
  distinctBrands(func: type(Stems)) @groupby(Stems.brand) {
    count(uid)
  }
}

returns

[
  {
    "@groupby": [
      {
        "Stems.brand": "Thomson",
        "count": 1
      },
      {
        "Stems.brand": "Easton",
        "count": 2
      },
      {
        "Stems.brand": "FSA",
        "count": 2
      },
      {
        "Stems.brand": "Syntace",
        "count": 2
      },
      {
        "Stems.brand": "OneUp Components",
        "count": 3
      },
      {
        "Stems.brand": "TruVativ",
        "count": 3
      },
      {
        "Stems.brand": "Renthal",
        "count": 4
      },
      {
        "Stems.brand": "PNW Components",
        "count": 5
      },
      {
        "Stems.brand": "Race Face",
        "count": 7
      },
      {
        "Stems.brand": "ENVE",
        "count": 9
      },
      {
        "Stems.brand": "Deity Components",
        "count": 38
      },
      {
        "Stems.brand": "Chromag",
        "count": 39
      },
      {
        "Stems.brand": "Industry Nine",
        "count": 48
      }
    ]
  }
]

but when I add sorting to the query like so:

{
  distinctBrands(func: type(Stems), orderasc: Stems.brand) @groupby(Stems.brand) {
    count(uid)
  }
}

I get only one Stem in the result:

[
  {
    "@groupby": [
      {
        "Stems.brand": "TruVativ",
        "count": 1
      }
    ]
  }
]

Adding sorting to DQL query reduces the number of results

All nodes have Stems.brand, which is confirmed by “brand” being a required field in the schema.

Groupby + Orderasc in Query
This post doesn’t answer the question “why does adding sorting to a DQL query with @groupby reduce results” as far as I can tell.

You can not sort a predicate inside a groupby body. The way groupby works what you wanna do is considered a “hack”. And sorting is even further.

We have plans to change the groupby. It will take time. And maybe sort inside the groupby response works. But we plan to make it work as usual. Without the "@groupby": [ response level.

BTW. Are you using 21.12???

Ok. Glad to hear that this might work eventually.

I’m not sure what you mean by that.

I’m using the Dgraph Cloud Explorer which is at v21.03.0 and I tried the same schema and query in dgraph/standalone:latest and it returned two results instead of one, oddly.