hasura / hasura/graphql-engine
console/graphiql: multiple order_by arguments are not constructed as array when using GraphiQL explorer, instead it constructs an object with multiple keys- this removes the order of the arguements
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
### Version Information
Server Version: v2.36.1-cloud.1
CLI Version (for CLI related issue):
### Environment
present in Cloud and OSS
### What is the current behaviour?
In generated SQL for query, the `order by` fields are arranged according the ascending order of field names used, as opposed to the order fields declaration
### What is the expected behaviour?
Generated SQL should use the order of fields mentioned, as in the query
### How to reproduce the issue?
1. create a sample table in free cloud version with neon db
```sql
create table if not exists phone_numbers (
id uuid NOT NULL DEFAULT uuid_generate_v1mc(),
"number" int not null unique,
"primary" boolean DEFAULT false,
verified boolean DEFAULT false,
created_at timestamp with time zone NOT NULL DEFAULT now(),
updated_at timestamp with time zone NOT NULL DEFAULT now());
```
2. insert values
```sql
insert into phn_numbers("primary","number",verified)
values (true,1,true),(true,2,false),(false,3,false);
```
3. now in graphql console run this query
```graphql
query MyQuery {
phone_numbers(order_by: {primary: desc, verified: desc, created_at: desc}) {
number
primary
verified
created_at
}
}
```
Click on the analyze button to see the generated sql, it would look something like this
```sql
SELECT
coalesce(
json_agg(
"root"
ORDER BY
"root.pg.created_at" DESC NULLS FIRST,
"root.pg.primary" DESC NULLS FIRST,
"root.pg.verified" DESC NULLS FIRST
),
'[]'
) AS "root"
FROM
(
SELECT
row_to_json(
(
SELECT
"_e"
FROM
(
SELECT
"_root.base"."number" AS "number",
"_root.base"."primary" AS "primary",
"_root.base"."verified" AS "verified",
"_root.base"."created_at" AS "created_at"
) AS "_e"
)
) AS "root",
"_root.base"."created_at" AS "root.pg.created_at",
"_root.base"."primary" AS "root.pg.primary",
"_root.base"."verified" AS "root.pg.verified"
FROM
(
SELECT
*
FROM
"public"."phone_numbers"
WHERE
('true')
ORDER BY
"created_at" DESC NULLS FIRST,
"primary" DESC NULLS FIRST,
"verified" DESC NULLS FIRST
) AS "_root.base"
ORDER BY
"root.pg.created_at" DESC NULLS FIRST,
"root.pg.primary" DESC NULLS FIRST,
"root.pg.verified" DESC NULLS FIRST
) AS "_root"
```
The expected order in `ORDER BY` Clause should be
`primary,verified,created_at`
### Screenshots or Screencast
its sorting based on `created_at` first which is resulting in `number 3` to appear at first,
but expected result is to `number 1` to appear at first when we sort according to `primary`, `verified`, `created_at` order
### Please provide any traces or logs that could help here.
### Any possible solutions/workarounds you're aware of?
### Keywords
`order_by`
Contributor guide
Research direction
Start in the console/graphiql Explorer handling for the reproduced order_by query, and compare the generated SQL with the declared field order. Done means the query using primary, verified, and created_at preserves that order in the generated ORDER BY clause and produces the expected result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, postgres, typescript
- Domain
- databases, frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100