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.