I’m using @groupby to list values stored in a field (type). I was expecting a single entry for every value, but DQL query is returning the value multiple times.
DQL Query:
{
var(func: type(TestDto)) @groupby(TestDto.type) {
node as count(uid)
}
result(func: uid(node)) {
type: TestDto.type
count: val(node)
}
}
Returns:
{
"result": [
{
"type": "MyType2",
"count": 3
},
{
"type": "MyType2",
"count": 3
},
{
"type": "MyType2",
"count": 3
}
]
}
I was expecting just one entry grouped as:
{
"result": [
{
"type": "MyType2",
"count": 3
}
]
}
Is that the expected behaviour? Or I’m missing some setting in the schema?
Info:
Dgraph v21.12.0, Deployed in kubernetes with dgraph/dgraph docker image.
Schema added to /admin/schema :
type TestDto @generate(
query: {
get: true,
query: true,
password: false,
aggregate: true
},
mutation: {
add: false,
update: false,
delete: false
},
subscription: false
) {
mrId: String! @search(by: [hash])
type: String @search(by: [exact])
}
Mutation adding test data (POST JSON to /mutate):
{
"set": [
{
"dgraph.type": "TestDto",
"uid": "_:x",
"TestDto.mrId": "724095000ed07",
"TestDto.type": "MyType2"
},
{
"dgraph.type": "TestDto",
"uid": "_:y",
"TestDto.mrId": "724095000ed08",
"TestDto.type": "MyType2"
},
{
"dgraph.type": "TestDto",
"uid": "_:z",
"TestDto.mrId": "724095000ed09",
"TestDto.type": "MyType2"
}
]
}
My goal is to also create a custom resolver with the groupby query to use from GraphQL.
Thanks!!