Order of columns data retrieved

Hello Monday community,

I have a small GraphQL query as below:

{
  vat_quarterly: boards(ids: 684144642) {
    groups(ids: "topics") {
      ...NumberDateFields2
    }
  }
}

fragment NumberDateFields2 on Group {
  items {
    column_values(ids: ["numbers", "date72", "mirror66"]) {
      text
    }
  }
}

The result I retrieve is as below(just a small snippet):

{
                "column_values": [
                  {
                    "text": "Courtney Stretton"
                  },
                  {
                    "text": "2021-08-31"
                  },
                  {
                    "text": "1"
                  }
                ]
              }
}

Now, the column ID mirror66 is actually a user’s name. In my Graph QL query I had added mirror66 at the end, but it appeared first in the result set for each row. Is there a way to achieve more definitive results, like the result order to match the columns order that the system was requested with?

So, here result should be in the order of numbers,date72 and then mirror66 which is the user’s name.

Could someone provide some insights as to how we can change this default behaviour?

Hey @vivek :wave:

Thanks for reaching out. That’s a great question!

To be transparent with you, I’m afraid that specifying the ID in a specific order will not result in a query that will return column results in the order you’ve mentioned. Specifying the ID acts as a way to limit the data your query will return, but doesn’t determine or sort the results.

Instead, would it make any sense to use the column id or title in order to sort the results in your application’s logic, as the results would always be paired like:

text: 1

What do you think?

-Alex

Thanks for replying and sorry for my late reply. It is mainly because of timezone difference.

I couldn’t understand your sorting idea. Could you elaborate? Actually, my graph QL query can have many groups to fetch from like below:

{
  new_key: boards(ids: new_board_id) {
    groups(ids: new_group_id) {
      ...NumberDateFields2
    }
  }
  vat_quarterly: boards(ids: 684144642) {
    groups(ids: "topics") {
      ...NumberDateFields2
    }
  }
}

@vivek

Thank you for circling back with me! No worries at all, thank you for being here with me :slight_smile:

I recommend returning the column IDs or Title within your API query, and then grouping the results within your code the way you’d like, based on the ID/Title, as our API will not currently perform that for you. So instead of just returning column_values { text }, you could retrieve column_values { text id title } and then interpret the results the way you’d like.

Does that make more sense?

-Alex

1 Like

Thanks Alex. That does seem to make sense to me. So you mean something like below:

{
  vat_quarterly: boards(ids: 684144642) {
    groups(ids: "topics") {
      ...NumberDateFields2
    }
  }
}

fragment NumberDateFields2 on Group {
  items {
    column_values(ids: ["numbers", "date72", "mirror66"]) {
      title,
      id,
      text
    }
  }
}

The result I get is as below:

"column_values": [
                  {
                    "title": "CS",
                    "id": "mirror66",
                    "text": "Courtney Stretton"
                  },
                  {
                    "title": "Deadline",
                    "id": "date72",
                    "text": "2021-08-31"
                  },
                  {
                    "title": "Count",
                    "id": "numbers",
                    "text": "1"
                  }
  ]

So you mean to define custom sort order in my application based on title or id value and sort those individual rows?

@vivek

Exactly! I’m glad we’re on the same page here, thank you for clarifiyng.

I realize this will involve some extra work on your end, but I hope this helps you achieve the end result that would be ideal for you.

-Alex

Thanks Alex for clarifying. It would involve a bit of extra work on our end but that’s fine if we could achieve the right order before processing.

Thanks for your time :slight_smile:

1 Like

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