Error; "Vars can be assigned only when grouped by UID attribute"

To facilitate better answering of questions, if you have a question, please fill in the following info. Otherwise, please delete the template.

What I want to do

Get a total count of groups. Using groupby to group by a predicate value, want to know how many groups there are for pagination.

What I did

This is the query I’m using:

query q($lexicon: string, $first: int) {
  var(func: type(Lexicon)) @filter(eq(Lexicon.language, "EN")) {
     Lexicon.lexicalEntries {
       LE as uid
    }
  }
  var(func: uid(LE)) @groupby(headword: LexicalEntry.headword, count)  {
    H as count(uid)
  }
  q(func: uid(H)) {
    total: val(H)
  }
}

I get the following error: "Vars can be assigned only when grouped by UID attribute".

I think this might be the fix? but looks like it hasn’t been merged into any release yet? feat(DQL): @groupby on scalar fields and count duplicate by minhaj-shakeel · Pull Request #7746 · dgraph-io/dgraph · GitHub

Dgraph metadata

21.03

Yes. I think it is.

It is in Dgraph v21.12.0 - Zion

How did you figure that out? Dgraph’s git branches are pretty hectic!