SELECT DISTINCT in Dgraph

Deja vu, I find myself back here again.

@dmai, has any of these ideas been explored?

UPDATE(for myself next time searching for this): too much to remember sometimes…

Here is the syntax query for the above data:

{
  distinctCountries(func: has(Country)) @groupby(Country) {
    # no need to select any fields, Country will be selected in the group by results
    # if you want to count the duplicates, use: count(uid)
  }
}

This syntax would return the following results:

{
  "data": {
    "distinctCountries": [
      {
        "@groupby": [
          {
            "Country": "Matrix"
          },
          {
            "Country": "Germany"
          },
          {
            "Country": "Brazil"
          },
          {
            "Country": "United States"
          }
        ]
      }
    ]
  }
}

And for reference, this can then be included as a custom GraphQL query using the @remoteResponse directive

2 Likes