How to count on nested predicate

Hello,

i am quite new to dgraph and graphql and trying to define some first queries on my schema.
now i’d like to count edges with a particular predicate but they are nested. could someone give me a hint how to do that?

here some details :
schema:
person → owns → animal.
animal → carriesHorns → boolean.

now i like to count:
how many animals do people own (on average) where the animal carriesHorns is true?

thanks!
Anne

1 Like

Try something like this.

{
  me(func: Type(Person)) @filter(something) {
    name
    count(owns) @filter(eq(carriesHorns, "true"))
  }
}
1 Like

hi,

sorry, I think I missed mentioning 1 nesting layer. we have some kind of n-ary relations / reification, therefore the schema is more like

Person - hasRelationship1 - MultirelationConcept
MultirelationConcept - hasRelationShip2- Person
Person - hasBooleanProperty - true

so I do not have to apply the filter the out-edges target of the first subject but on the object of the second (MultirelationConcept - hasRelationShip2- Person(filter boolean property=true))

@MichelDiz do you have any suggestion with this additional nesting layer?

Not sure, I’m confused with your examples. Maybe this?

{
  me(func: Type(Person)) @filter(something) {
    name
     hasRelationship1 { 
      count(hasRelationship2) @filter(eq(hasBooleanProperty, "true")) { 
         uid  name 
       }
     }
  }
}

If you share an example(sample) of your dataset reflecting exactly that structure would help a lot.

Cheers.