How to create a feed of posts?

Hi!

I’m looking at using Dgraph for a social network. I’ve been trying it out for a few hours and it seems great but I’ve stumbled upon a road block.

One of the things I need to be able to do is to query the most recent x posts from a list of users that I follow. Note that it’s not the most recent x posts of each person but the most recent x across all of their posts.

To clarify a bit further, this is a simplified version of what I can currently get:

{
    "me": {
        "friends": [
            {
                "user2': {
                    "posts": [
                      {post10},
                      {post5},
                      ...
                    ]
                }
            },
            {
                "user3': {
                    "posts": [
                      {post9},
                      {post4},
                      ...
                    ]
                }
            },
            {
                "user4': {
                    "posts": [
                        {post8},
                        {post3},
                        ...
                    ]
                }
            },
        ]
    }
}

What I need is something like this (assuming x = 4):

{
    "me": {
        "posts": [
            {post10},
            {post9},
            {post8},
            {post5}
        ]
    }
}

I have a feeling that it’s either I’m missing something basic or I need a complicated query to get what I need. If you guys can help me create a query for this, that would be great.

This is an interesting query. You can use variables to achieve this. @ashwin95r can explain how it would work with them.

{
 var(id: <my-id>) {
  friends {
   A as posts (orderdesc: time-stamp, first: x) {
    B as time-stamp
   }
  }
 }

 TopPostsFromMyFriends(id: var(A), orderdesc: var(B), first: x) {
   <whatever-fields-you-need>
 }
}

Hope this helps @jansenignacio. Let us know how it works for you!

3 Likes

Thanks for this. It steered us to the right path. We ran into other issues which we’ll put somewhere else (like as a bug report on github or as a separate topic here)

1 Like

Yes. Please do file any issues that you face and we’ll fix them asap.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.