How to return "edges" count and whether "edge" between two nodes exists?

I’m working on a social network using a graph-db, I have just migrated from a different graph-db provider so I already have my own schema, except that it is a bit different.

So far I’m having issues with retrieving the count (int) of the edges (relashionships) between two nodes and whether an edge does exists or not (Boolean).

As for the nodes I have the (User) node and the (Post) node, so I’m trying to retrieve the count of Posts created by the User, count of Users following User and whether User is following User and in the Post (type) I have "likes_count", "comments_count" and "user_liked" (Boolean) that I want to retrieve with each query too.

My schema looks like this.

type User {
  id: ID
  created_at: String
  user_id: ID! @id
  username: String! @id
  is_private: Boolean
  #count of posts created including the one reposted (shared)
  created_posts_count: Int #THIS
  following_count: Int  #THIS
  followers_count: Int #THIS
  following: Boolean #THIS
  followed_by: Boolean #THIS
  blocked_by: Boolean #THIS
}

type Post{
  post_id: String
  text: String
  likes_count: int #THIS
  comments_count: int #THIS
  post_author: User 
  user_created: Boolean  #THIS
  user_liked: Boolean  #THIS
  user_favourited: Boolean  #THIS
  user_shared: Boolean  #THIS
  user_commented: Boolean #THIS
}

the properties that I’m interested about are the ones that have (#THIS) next to them.

Can they be extended with DQL so these properites are retrieved with each query that returns result for User and Post node?

1 Like

Theoretically, yes. But a determining factor is: Do you plan on using auth rules to control the querying of either the posts or the users? If yes, then the DQL count will not be accurate. But it can still be done with GraphQL in a lambda that respects query rules.

The way to make these properties either with DQL or GraphQL resolvers is inside lambda fields.

Yes. I forgot to mention Authentication. I will be relying on JWT to pass the uid, which will have to be passed to the query or the node type in the schema. Can the uid from JWT be passed to the lambda fields ?

That makes it more complicated…

What about verification? I’m using Firebase for authentication and I need to verify the JWT, only after verifying can I get the decodedToken with (uid, sub, emal…). Can I import the FirebaseAdminSdk inside the lambda js script?