hasura / hasura/graphql-engine
Ordering issues in action queries
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
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:
```gql
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:
```gql
{
"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:
```gql
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):
```gql
{
"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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the two GraphQL queries against a Hasura action whose REST response is ordered and whose result includes a foreign-key relationship. Compare the returned list order with and without the nested customer selection; done means selecting the relationship no longer changes the upstream order.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100