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

**URL:** <https://discuss.dgraph.io/t/how-to-return-edges-count-and-whether-edge-between-two-nodes-exists/16661>\
**Category:** Dgraph\
**Tags:** graphql, schema, dgraph\
**Created:** [January 25, 2022, 10:55pm UTC](https://discuss.dgraph.io/t/how-to-return-edges-count-and-whether-edge-between-two-nodes-exists/16661 "2022-01-25T22:55:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Admin\_16](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/admin_16/32/9499_2.png) [@Admin\_16](https://discuss.dgraph.io/u/Admin_16)\
**Post date:** [January 25, 2022, 10:55pm UTC](https://discuss.dgraph.io/t/how-to-return-edges-count-and-whether-edge-between-two-nodes-exists/16661/1 "2022-01-25T22:55:49Z")

</div>

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.

```auto
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?

---

<div class="post-metadata">

**Author:** ![amaster507](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/amaster507/32/4123_2.png) [@amaster507](https://discuss.dgraph.io/u/amaster507)\
**Post date:** [January 26, 2022, 1:43am UTC](https://discuss.dgraph.io/t/how-to-return-edges-count-and-whether-edge-between-two-nodes-exists/16661/2 "2022-01-26T01:43:01Z")

</div>

> [@Admin\_16](#):
>
> Can they be extended with DQL so these properites are retrieved with each query that returns result for User and Post node?

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.

---

<div class="post-metadata">

**Author:** ![Admin\_16](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/admin_16/32/9499_2.png) [@Admin\_16](https://discuss.dgraph.io/u/Admin_16)\
**Post date:** [January 26, 2022, 2:22am UTC](https://discuss.dgraph.io/t/how-to-return-edges-count-and-whether-edge-between-two-nodes-exists/16661/3 "2022-01-26T02:22:56Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![amaster507](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/amaster507/32/4123_2.png) [@amaster507](https://discuss.dgraph.io/u/amaster507)\
**Post date:** [January 26, 2022, 4:12am UTC](https://discuss.dgraph.io/t/how-to-return-edges-count-and-whether-edge-between-two-nodes-exists/16661/4 "2022-01-26T04:12:40Z")

</div>

That makes it more complicated…

> [@Auth variables access on custom resolver](http://discuss.hypermode.com/t/auth-variables-access-on-custom-resolver/13893/3):
>
> Since the use of atob is deprecated (see [here](https://newbedev.com/using-javascript-s-atob-to-decode-base64-doesn-t-properly-decode-utf-8-strings) to see why), I am using Buffer instead to decode the JWT payload. Unfortunately, it seems that Dgraph Lambda does not support Buffer out of the box and thus you would have to deploy locally using webpack to include Buffer within the bundle. Here’s a snippet which works for me to decode the payload: Install Buffer yarn add buffer Parsing token and returning the payload Get the token from the authHeader param with const token = authHeader.value. c…

---

<div class="post-metadata">

**Author:** ![Admin\_16](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/admin_16/32/9499_2.png) [@Admin\_16](https://discuss.dgraph.io/u/Admin_16)\
**Post date:** [January 26, 2022, 4:39am UTC](https://discuss.dgraph.io/t/how-to-return-edges-count-and-whether-edge-between-two-nodes-exists/16661/5 "2022-01-26T04:39:16Z")

</div>

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?
