Help on error: Vars can be assigned only at root when grouped by Value

What I want to do

Hi guys, I am just starting with Dgraph and I am experiencing “beginners’ troubles” :blush:
I’m following this blog post Build a Realtime Recommendation Engine: Part 2 - Dgraph Blog which, of course, I aware it is kinda outdated for Dgraph Zion.
The part 1 went more or less smoothly, but now I’m stuck on an error I don’t really understand:

{
  "name": "t",
  "url": "https://dgraph.docker/query?timeout=20s",
  "errors": [
    {
      "message": ": Vars can be assigned only at root when grouped by Value",
      "extensions": {
        "code": "ErrorInvalidRequest"
      }
    }
  ]
}

What I did

I have successfully set movielens schema and data on Docker with the command:

dgraph live -f out.rdf.gz -s movielens.schema -c 1 --zero=dgraph-zero:5080 --alpha dgraph-alpha:9080

Running this DQL query:

{
  var(func: uid(0x2711)) {  # 1
    rated @groupby(genre) {
      gc as count(uid)
    }

    a as math(1)
    seen as rated @facets(r as rating) @facets(ge(rating, 3)) { # 2
      ~rated @facets(sr as rating) @facets(ge(rating, 3)) {   # 3
        user_score as math((sr + r)/a) # 4
      }
    }
  }

  var(func: uid(user_score), first:30, orderdesc: val(user_score)) { #5
    norm as math(1)
    rated @filter(not uid(seen)) @facets(ur as rating) { # 6
      genre {
        q as math(gc)   # 6.1
      }
      x as sum(val(q))  # 6.2
      fscore as math((1+(x/100))*ur/norm) # 7
    }
  }

  Recommendation(func: uid(fscore), orderdesc: val(fscore), first: 10) { # 8
    val(fscore)
    name
  }
}

Can you help me to understand what I’m missing?

Thank you in advance

Dgraph metadata

dgraph version

Dgraph version :
Dgraph codename :
Dgraph SHA-256 : a0722f00f4a6bebb5e5cfdcd49bab68ca29e5ae6eeeb7853a3e1289518ac8b3c
Commit SHA-1 :
Commit timestamp :
Branch :
Go version : go1.17.7
jemalloc enabled : false

Is genre a value or an edge?

Edge.

{
  film (func: has(genre)) {
    uid
    name
    genre {
      uid
      name
    }
  }
}
{
  "data": {
    "film": [
      {
        "uid": "0x30d41",
        "name": "Toy Story (1995)",
        "genre": {
          "uid": "0x186a3",
          "name": "Animation"
        }
      },
      {
        "uid": "0x30d42",
        "name": "GoldenEye (1995)",
        "genre": {
          "uid": "0x186a1",
          "name": "Action"
        }
      },
      {
        "uid": "0x30d43",
        "name": "Four Rooms (1995)",
        "genre": {
          "uid": "0x186b0",
          "name": "Thriller"
        }
      },
...

What version are you using? I wasn’t able to find that error in the code

Just this one


Update.

I have found it

So, this behavior was changed. You need to modify that query manually. The tutorial was made way before that change.