Select distinct values / deduplicate

I have this data/nodes :

 {name: "Tom" , age: 42 },
 {name: "Jerry", age: 12 },
 {name: "Tom",  age: 35 }

I would like to run a DQL query that returns all unique names: ["Tom", "Jerry"]

It looks like groupBy sort of does this, but it is not available in graphQL and only DQL. This basically means you need to do a @custom dql query. The problem is that you can’t use @auth on a custom query, so that only leaves putting a custom DQL within a custom mutation @lambda.

Hopefully this is a new feature request they plan on adding.


I have tried to use groupby, like this:

    people as var(func: has(dgraph.type, Person))
    nameCounts as var(func: uid(people) ) @groupby(name) { count(uid)}

(doesn’t work)
The problem is that you can’t assign this groupby to a variable, which I need to keep processing.
It does work if it is your final result

1 Like