How to achieve this query in DQL or GraphQL?


I’m new to DGraph. I’m experimenting with this database for 2 weeks with a lot of success so far.

I’m migrating an app from AWS Neptune, the queries are written in Gremlin which is a very flexible query language.

The goal is to migrate an app from AWS Cloud to Bare Metal Hosted in a first time, and may be in DGraph cloud later.

I’ve tested other Gremlin Databases like JanusGraph (both Cassandra and ScyllaDB), OrientDB, ArcadeDB etc.

So far DGraph is the best in term of performance, stability, and overall features. I had a lot of wow effect moments working with DGraph and I would like to make it work for my project.

Not only I want to migrate this app, but I could also improve it a lot with all the capabilities of DGraph.

The problem I have right now is that I have difficulties translating some Gremlin traversals in GraphQL or DQL. These queries are vital for the project.

I’m working with the latest DGraph version available on Docker.

Here is the kind of traversal that I don’t figure how to translate in DQL or GraphQL:

Let’s suppose I, as a User follows a list of other Users. How to get the last 50 posts of the users I follow, ordered by publication date?

This kind of GraphQL query does not really work like I want, because the posts are not globally ordered, but locally under each user that posted them:

query GetPosts {
	queryUser(filter: { alias: { eq: "tza92" } }) {
		follows {
				post(order: { desc: pubStamp }, first: 50) {

In fact it gives me the list users I follow with 50 posts for each of them, ordered locally.

I’m not very well versed in GraphQL, I’m learning it with DGraph. I don’t know if it’s possible.

So I thought that may be I should try in DQL which seems more flexible. Unfortunately, I didn’t see any example or tutorial to lead me to the solution.

So if you could help me, by giving me some tips and some links to tutorials and examples on how to achieve this kind of queries in DQL or GraphQL, it would be very helpful.

Thank you very much!

This should get you started. On mobile now so tag me later if you need more guidance.

Thanks a lot!

It works, and it’s fast!

I really appreciate your help.

1 Like

Thanks, @tza92 for sharing your positive feedback on your journey with Dgraph. Please post your progress and pain points, we will be happy to help. I think @amaster507 gave you the right direction.

I’m struggling with another query.

Let’s suppose that I have this hierarchy in pseudo types:

User {
  alias: "tza92"
  curations: [
       title: "..."
       users: [
             alias: "...",
             posts: [
                {"title": "post 2", timestamp: 987654321 },
                {"title": "post 1", timestamp: 987654320 }

So a User has a list of curations, each curation list regroups a list of Users, and each user has a list of posts.

I want to retrieve for a given user, its curations list, and for each curation list, its title and the posts published by its users, ordered by published stamps.

So basically I want to squizz the intermediate level of users between a curation list and the posts.

Any tips on how I can achieve this in one DQL query?

What I can do is one query to retrieve the list of curation lists, and for each curation list one query to retrieve the posts. But it may end in a lot of queries.

Is it possible to perform this in one single query?