Does order in a DQL query matter?

Hi @amanmangal and @MichelDiz,

Thanks! Clearly the filter is needed to get the right counts here, so just focusing on the order - above vs. below the node.

I can’t share my query, but I can replicate it. I followed the first steps 1-6 in the DGraph Tour: Graphs | Intro | Dgraph Tour

Here’s the equivalent query I’m running:

{
  michael(func: eq(name, "Michael")) @recurse(depth:10){
    name
    age
    owns_pet
    friend~
    friend @filter(NOT eq(name, "Sarah")) 
  }
}

The full graph appears (except Sarah).

Equivalent to Test 2 above:
The count is above the friend node.

{
  michael(func: eq(name, "Michael")) @recurse(depth:10){
    name
    age
    owns_pet
    friend~
    count(friend @filter(NOT eq(name, "Sarah")))
    friend @filter(NOT eq(name, "Sarah")) 
  }
}

Adding the count with the filter causes a ton of the graph to not return

Equivalent to Test 4 above:
The count is below the friend node.

{
  michael(func: eq(name, "Michael")) @recurse(depth:10){
    name
    age
    owns_pet
    friend~
    friend @filter(NOT eq(name, "Sarah"))
    count(friend @filter(NOT eq(name, "Sarah")))
  }
}

The full graph comes back here.

I also tried putting the count inside the friend node:

{
  michael(func: eq(name, "Michael")) @recurse(depth:10){
    name
    age
    owns_pet
    friend~
    friend @filter(NOT eq(name, "Sarah")) {
      count(uid)
    }
  }
}

But I get this error “recurse queries require that all predicates are specified in one level”:

And I tried putting the filter at the function declaration:

{
  michael(func: eq(name, "Michael")) @recurse(depth:10) @filter(NOT eq(name, "Sarah")){
    name
    age
    owns_pet
    friend~
    friend 
    count(friend)
  }
}

But the filter didn’t take effect.

@MichelDiz I haven’t used variables before, I’m still playing around with converting what I’ve got here to something more like what you recommended.

Any thoughts on the before vs. after oddness or recommendations on a better way to do this?

Thanks,
Ryan