How to user filter with variable?

I want to filter ~liked user who follows an author of posts.

{
  q(func: has(post_id)){
    post_id
    ~authored{
       follower as follows
    }
    ~liked @filter(uid(follower)) {
      user_id
    }
  }
}

but I got

{
  "data": {
    "q": [
      {
        "post_id": "post_01"
      }, ...
    ]
  },
  "extensions": {
    "server_latency": {
      "parsing_ns": 45547,
      "processing_ns": 6163104,
      "encoding_ns": 570999,
      "assign_timestamp_ns": 572197,
      "total_ns": 7445194
    },
    "txn": {
      "start_ts": 63330
    },
    "metrics": {
      "num_uids": {
        "": 24,
        "_total": 920,
        "follows": 32,
        "post_id": 288,
        "user_id": 0,
        "~authored": 288,
        "~liked": 288
      }
    }
  }
}

how can I get the number of user who like a post and also follows the author?

Something like this

{
  var(func: has(post_id)){
    post_id
    follower as ~authored
    wholiked as ~liked
  }

  users(func: uid(wholiked)) @filter(uid_in(follows, uid(follower))) {
     user_id
  }
  
}

I’m having trouble getting the results I want with your current query. I believe my explanation may have been insufficient, so I wanted to clarify.

My schema is set up like this:

What I’m trying to do is get the score for each post based on the number of followers of the author who liked that post. Specifically, I’m using the count function with the ~liked predicate, filtered by the UID of the follower.

so with following query. I can get one the score I want about one specific post.

{
	var(func: eq(post_id,post_01)){
		post_id
    ~liked{
			liked_user as  user_id
  	}
    ~authored{
			 ~follows{
				follower as user_id
      }
    }
  }
  var(func: uid(liked_user))@filter(uid(follower)){
  fol_like as user_id
  }
  q(func: eq(post_id,post_01)){
    post_id
    count(~liked)
    ~authored{
      score : count(~follows @filter(uid(fol_like)))
    }
	}
}

However, However, I’m not just looking for the score of one post. I want to calculate the score for every post that I select. Is it possible? Thanks for your help.

​ ​

2 3 / 3

​ ​

Sorry the delay. Lots going on. Well, this is not possible. I mean, The best and precise way of checking the scores is individually. If you use the same variable for a wide query(mean, looking for all posts and trying to aggregate for each) this wont work. I have an issue to introduce “foreach” and that would solve that problem. As Dgraph would apply the same query, but individually. That means for each node found in the root query Dgraph would isolate the variables.

Until there you have to narrow your query.

Cheers.

PS. Dgraph queries are “mapped based”. You may be able to aggregate each of the posts using the same structure(it depends of the levels too). But the Root needs to be the same map as the other blocks.

Share some JSON examples of your data and I can explore it for you.