Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ordering issues in action queries #6695

Open
Luigi-98 opened this issue Mar 22, 2021 · 2 comments
Open

Ordering issues in action queries #6695

Luigi-98 opened this issue Mar 22, 2021 · 2 comments
Labels
a/api/graphql c/actions Related to actions c/server Related to server k/bug Something isn't working k/v3-beta p/high candidate for being included in the upcoming sprint

Comments

@Luigi-98
Copy link

Hi,

It seems that hasura actions are not preserving the original order of the json object received via REST endpoint.

For example, I'm using a REST server which returns a table with data already ordered by the field total_count (descending).
total_count is a computed field, customer_idx is a foreign key to the customer table.

Query 1:

query {
  get_customer_stats(ticket_filters: {}) {
    total_count
    customer_idx
  }
}

Results are correctly ordered here by total_count (descending) as passed by the REST server:

{
  "data": {
    "get_customer_stats": [
      {
        "customer_idx": 2,
        "total_count": 8
      },
      {
        "customer_idx": 3,
        "total_count": 5
      },
      {
        "customer_idx": 1,
        "total_count": 4
      },
      {
        "customer_idx": 4,
        "total_count": 1
      }
  }
}

Query 2:

query {
  get_customer_stats(ticket_filters: {}) {
    total_count
    customer_idx
    customer {
      name
    }
  }
}

Now hasura is changing the order of results, ordering by customer_idx (customer is a relationship to a foreign key):

{
  "data": {
    "get_customer_stats": [
      {
        "total_count": 4,
        "customer_idx": 1,
        "customer": {
          "name": "Luigi Rossi"
        }
      },
      {
        "total_count": 8,
        "customer_idx": 2,
        "customer": {
          "name": "Carlo Bianchi"
        }
      },
      {
        "total_count": 5,
        "customer_idx": 3,
        "customer": {
          "name": "Mario Verdi"
        }
      },
      {
        "total_count": 1,
        "customer_idx": 4,
        "customer": {
          "name": "Matteo Aranci"
        }
      }
  }
}

Other tests

  • Ordering does not depend on the order of the fields in the query
  • Ordering does not depend on any of the fields in the original table, only the one which the relationship is based on
@tirumaraiselvan
Copy link
Contributor

I think it's because when you perform a join of your actions result with table, ordering is lost. This happens at the PG layer itself so not sure if there is any easy fix...

@coco98 coco98 added a/api/graphql c/actions Related to actions labels Oct 7, 2021
@0x777 0x777 added c/server Related to server p/high candidate for being included in the upcoming sprint labels Oct 7, 2021
@manasag manasag added k/bug Something isn't working k/v3-beta labels Apr 11, 2024
@manasag
Copy link
Contributor

manasag commented Apr 16, 2024

Hi, I want to update that we are launching Hasura V3 (DDN) this month. In V3, we are able to rebuild the core engine in a manner that feature wise, works consistently across intents (data source, actions, code etc), and for any kind of joins. This problem is now solved in V3.

I would highly suggest to join us to see the full power of Hasura DDN at the Hasura Dev Day on April 16 🎉. Sign up here: https://hasura.io/dev-day. Can't make it? Sign up anyway and we'll send you the recording.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a/api/graphql c/actions Related to actions c/server Related to server k/bug Something isn't working k/v3-beta p/high candidate for being included in the upcoming sprint
Projects
None yet
Development

No branches or pull requests

5 participants