hasura / hasura/graphql-engine
Incorrect ID field values in GraphQL
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
### Version Information
Server Version: 2.34.0 (also tested on 2.25.0)
### Environment
OSS
### What is the current behaviour?
The values for `id` fields within Hasura are incorrect and different from those in the database and are not unique.
### What is the expected behaviour?
The values for the `id` fields (and all fields) should reflect exactly what is in the database.
### How to reproduce the issue?
1. Query the data in Hasura
2. Query the data directly using SQL
3. Confirm that the values of the `id` field are not consistent.
### Please provide any traces or logs that could help here.
The fields appear to be typed properly with the `id` field being primary and unique:

Direct SQL query:
```
select id, ast_number from minorplanet order by id limit 10;
```

GraphQL Query:
```
query MyQuery {
minorplanet(order_by: {id: asc}, limit: 10) {
id
ast_number
}
}
```
Result:
```json
{
"data": {
"minorplanet": [
{
"id": 72057594037948900,
"ast_number": 1
},
{
"id": 72057594037948900,
"ast_number": 2
},
{
"id": 72057594037948900,
"ast_number": 3
},
{
"id": 72057594037948900,
"ast_number": 4
},
{
"id": 72057594037948900,
"ast_number": 5
},
{
"id": 72057594037948900,
"ast_number": 6
},
{
"id": 72057594037948910,
"ast_number": 7
},
{
"id": 72057594037948910,
"ast_number": 8
},
{
"id": 72057594037948910,
"ast_number": 9
},
{
"id": 72057594037948910,
"ast_number": 10
}
]
}
}
```
The generated SQL from the GraphQL query:
```
SELECT
coalesce(
json_agg(
"root"
ORDER BY
"root.pg.id" ASC NULLS LAST
),
'[]'
) AS "root"
FROM
(
SELECT
row_to_json(
(
SELECT
"_e"
FROM
(
SELECT
"_root.base"."id" AS "id",
"_root.base"."ast_number" AS "ast_number"
) AS "_e"
)
) AS "root",
"_root.base"."id" AS "root.pg.id"
FROM
(
SELECT
*
FROM
"public"."minorplanet"
WHERE
('true')
ORDER BY
"id" ASC NULLS LAST
LIMIT
10
) AS "_root.base"
ORDER BY
"root.pg.id" ASC NULLS LAST
) AS "_root"
```
This appears to be my only table facing this issue, so I suspect some configuration is incorrect. But I see no clear error in any configuration.
### Any possible solutions/workarounds you're aware of?
I have tried the "Reloading the databases" option, but that did nothing.
### Keywords
Contributor guide
Research direction
No source files or tests are named. Start by reproducing the discrepancy with the provided direct SQL query and GraphQL query, then compare the PostgreSQL schema, returned values, and generated SQL. Done means the GraphQL id values match the database values and remain unique for this table.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, postgresql
- Domain
- api, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100