Search code examples
dgraph

Query for a node, filtering using uid of child nodes (relations)


If have a schema "Like" that has relations to User Schema (user_id) and Post Schema (object_id). How can I query for the "Like" nodes that have user_id = (some_uid) and object_id = (some_uid).

I am using dgraph-io/dgraph-js.

User Schema               Post Schema             Like Schema

uid                       uid                     uid
first_name                type                    object_id (maps post)
last_name                 content                 user_id (maps user)
email                     title
created_at


Solution

  • Try this

    {
      likes(func: has(like.object_id)) @filter(uid_in(like.object_id, 0x2) and uid_in(like.user_id, 0x3)){
        like.object_id {
          uid
          post.type
          post.content
          post.title
        }
        like.user_id{
          uid
          user.email
          user.first_name
          user.last_name
        }
      }
    }