graphql-engine
graphql-engine copied to clipboard
Ordering issues in action queries
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
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...
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.