Threaded comment pagination

Hello! I’m evaluating GraphQL for use to power a forum software. The main reasons we’re looking into DGraph are for threaded comments and real-time recommendations. I found the two blog posts for recommendations which were great, but I’m struggling to find a solution for paginating a threaded comment section. Here’s an outline of what I’m trying for a POC:

Each comment has a parent comment (except the ‘root’) and an author.
Each user can like a comment.

That’s about it, I’ve generated a 100 node tree by having users randomly like / author posts to test this out.

I’ve had some success with:

var(func: has(content)) {
  likeCount as count(liked_by: ~likes)
me(func: eq(content, "Post 6"))
@recurse(depth: 3){
  children: ~parent(orderdesc: val(likeCount), first: 4)

This returns a subgraph of posts in response to an arbitrary parent, to a given breadth (4) and depth (3), which is great!
The issue with this approach is that I have no control over how many comments are returned. Depending on how the graph looks it can return anywhere from 1, to breadth^depth posts.

Since I’m quite new to DQL I was wondering if anyone knew a good way to limit this to a fixed number of posts, say 20 or 50 to more closely match standard pagination behaviour? I spent some time tinkering with variable propagation to track the number of posts returned, but haven’t had any luck yet.

It would be cool to be able to persist and modify some counter variable during recursion, or even better to provide a custom algorithm to traverse the graph.

Thanks for your help!

PS I tried to upload the file I used to generate the graph in case you wanted to try it yourself, but new users can’t upload files. Let me know if you’d like the file and I can try to send it