hasura / hasura/graphql-engine
GraphQL API: serial column truncated (INT8)
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
This bug was reproduced using CockorachDB, but it's probably reproducible with other databases as well.
When creating a column as `SERIAL`, CockorachDB uses by default `INT8` and the `unique_rowid()` function to generate a value.
Steps:
* `CREATE TABLE "public"."test" ("id" serial NOT NULL, "name" text NOT NULL, PRIMARY KEY ("id") );`
* `INSERT INTO "test" VALUES(DEFAULT, 'test');`
* `SELECT * FROM "test";`
| id | name |
| ------------------------ | --------|
| 800203939831775233 | test |
* Go to browse rows

The same issue happens on Postgres if I create a column of type `BIGINT` and I insert a row with the value `800203939831775233`.
It returns from the server as `800203939831775200`.
CockroachDB makes use of GraphQL to retrieve the rows in Browse Rows.
Postgres makes use of RQL to retrieve the rows in Browse Rows.
But in both cases the issue is present.
GraphQL API
```
curl 'http://localhost:8080/v1/graphql' \
-H 'Accept: */*' \
-H 'Accept-Language: en-US,en;q=0.9' \
-H 'Cache-Control: no-cache' \
-H 'Connection: keep-alive' \
-H 'Origin: http://localhost:3000' \
-H 'Pragma: no-cache' \
-H 'Referer: http://localhost:3000/' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Site: same-site' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36' \
-H 'content-type: application/json' \
-H 'sec-ch-ua: "Google Chrome";v="105", "Not)A;Brand";v="8", "Chromium";v="105"' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'sec-ch-ua-platform: "macOS"' \
-H 'x-hasura-admin-secret: undefined' \
--data-raw '{"query":"query TableRows {\n Posts (limit: 5,offset: 0) {\n content\ntitle\npostId\nuserId\n }\n Posts_aggregate {\n aggregate {\n count\n }\n }\n }","variables":null,"operationName":"TableRows"}' \
--compressed
```
Response
```
{
"data": {
"Posts": [
{
"content": "asd",
"postId": 800192313374998500,
"title": "asd",
"userId": 800178894006583300
},
{
"content": "asd",
"postId": 800204434364006400,
"title": "asd",
"userId": 121212
}
],
"Posts_aggregate": {
"aggregate": {
"count": 2
}
}
}
}
```
RQL
```
curl 'http://localhost:8080/v2/query' \
-H 'Accept: */*' \
-H 'Accept-Language: en-US,en;q=0.9' \
-H 'Cache-Control: no-cache' \
-H 'Connection: keep-alive' \
-H 'Origin: http://localhost:3000' \
-H 'Pragma: no-cache' \
-H 'Referer: http://localhost:3000/' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Site: same-site' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36' \
-H 'content-type: application/json' \
-H 'sec-ch-ua: "Google Chrome";v="105", "Not)A;Brand";v="8", "Chromium";v="105"' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'sec-ch-ua-platform: "macOS"' \
-H 'x-hasura-admin-secret: undefined' \
--data-raw $'{"type":"bulk","source":"Postgres","args":[{"type":"select","args":{"source":"Postgres","table":{"schema":"public","name":"Users"},"columns":["id","name","created_at","updated_at"],"limit":5}},{"type":"run_sql","args":{"source":"Postgres","sql":"SELECT\\n reltuples::BIGINT\\n FROM\\n pg_class c\\n JOIN\\n pg_namespace n ON c.relnamespace = n.oid\\n WHERE\\n c.relname = quote_ident(\'Users\') AND n.nspname = quote_ident(\'public\');","cascade":false,"read_only":true}}]}' \
--compressed
```
Response
```
[
[
{
"id": 1,
"name": "john doe",
"created_at": "2022-09-27T09:17:39.123532+00:00",
"updated_at": "2022-09-27T09:17:39.123532+00:00"
},
{
"id": 800203939831775200,
"name": "asd",
"created_at": "2022-09-27T10:12:04.308837+00:00",
"updated_at": "2022-09-27T10:12:04.308837+00:00"
}
],
{
"result_type": "TuplesOk",
"result": [
[
"reltuples"
]
]
}
]
```
Contributor guide
Assessment
This issue has not been assessed yet.