Dgraph: JSON in the same order that it was request

Created on 24 Jul 2017  路  5Comments  路  Source: dgraph-io/dgraph

Hi, I just started playing around with Dgraph, and I must say it's awesome :)

Dunno if it's just a bug on the tutorial playground, but, it would be great if, like in GraphQL, the response comes in the same order that it was requested.

In the michael_friends_and_pet query, since there are a lot of names and friends you kinda get lost with the unordered response.

So, if you call

{
    name
    age
    friend {
          name
          age
    }
}

it would be great if the response was

{
      "name": "john doe"
     "age": 32
     "friend": {
          "name": "jane doe"
          "age": 22
      }
}

and not

{
     "age": 32
     "friend": {
          "age": 22
          "name": "jane doe"
      }
     "name": "john doe"
}

All 5 comments

@KadoBOT the response is not "unordered" - actually JSON keys are ordered alphabetically (ascending). If you look at the results it may be a bit confusing, but if you're processing it, this shouldn't be a problem.

GraphQL spec states that results should be ordered. It was changed from _must_ to _should_, because by definition JSON object _is an unordered set of name/value pairs_.

I'll check this out - if it won't complicate the code, we can switch to ordering from query.

It would be great :) If not worth switching, at least somewhere where we can pass an option and select how we want the JSON to be ordered.

To understand the why behind this request, is there a reason why you want JSON to be ordered in a particular way? How does it help you?

Let's take GraphQL as the example. The JSON will return the exact same way you requested it, so it feels kinda natural to know which field is related to each key in the query. It's not a big deal TBH, but IMO, I would like even more if the result order was the query order.

While working with the tutorials I felt 'lost' sometimes when something like this happened. Although it's alphabetically ordered, my biggest issues were: What name belongs to a friend and what name belongs to a friends friend. And, the name showing after a big and long nested list.
Query:

{
  name
  age
  friends: {
    age
    name
    friends: {
      name
      age
    }
  }
}

and the result was:

{
  age: 50,
  friends: [
    {
      age: 23,
      friends: [
        {
          age: 50,
          name: 'B'
        },
        {
          age: 50,
          name: 'B'
        },
      ],
      name: 'A'
    },
    {
      age: 23,
      friends: [
        {
          age: 50,
          name: 'B'
        },
        {
          age: 50,
          name: 'B'
        },
      ],
      name: 'A'
    }
  ],
  name: '1'
}

Hmm... okay, makes sense. We'll fix this behavior.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MichelDiz picture MichelDiz  路  3Comments

jimanvlad picture jimanvlad  路  5Comments

djdoeslinux picture djdoeslinux  路  4Comments

pjebs picture pjebs  路  4Comments

marvin-hansen picture marvin-hansen  路  4Comments