Is it possible add count directive to a reverse edge?

the schema:

{
  type User {
    username
  }

  type Tweet {
    author
  }

  author: uid @reverse .
}

query my own tweets:

{
  my_twwet(func: uid(my_uid)) {
    tweets_num: count(~auhtor)
  }
}

for author is not a list type, so it can’t be with @count directive (right?), I’m afraid the query will be slow when the sets is large. so what exactly need to do in this scenario ?

Is it possible add count directive to a reverse edge?

Yes, and you did it.

count directive is useful if you have many incoming/outgoing edges and you wanna for example “return post with 1k likes” from root params. That directive will create a count indexation to make this type of query fast. For you case as it looks like one to one relation that directive is useless.

You can use it, it won’t be slow as it will always be 1 count.

This is the way.

tweets_num: count(~auhtor)

@MichelDiz it’s a one-to-many relationships, user can have many tweets:

{
  set {
    _:tweet1 <author> _:user1 .
    _:tweet2 <author> _:user1 .
    _:tweet3 <author> _:user1 .
    _:tweet4 <author> _:user1 .
  }
}

Nope, following your schema. It is many-to-one. The Tweet is the main(parent) entity of your schema. So, many tweets can have a single author. In the case of the reverse index, it reverts. It turns to one-to-many. But this isn’t the main model.

If you wish a user-based model, you should change your schema to

{
  type User {
    username
    tweets
  }

  type Tweet {
    content
  }

  tweets: uid @reverse .
}