breaking: encode bigint and bigserial postgres types as strings in response (fix #633) (#640)

This is breaking change where bigint and bigserial Postgres types will be encoded as GraphQL String types, as opposed to Int as present in earlier releases.

Input types were already encoded as String.

This is achieved by selecting `bigint` and `bigserial` columns as `text`s in the SQL query: `select "big_id"::text ..` instead of `select "big_id" .. `.

Reason for that change is outlined in #633 where JavaScript cannot decode 64 bit Integers.
This commit is contained in:
Rakesh Emmadi 2018-10-05 10:46:21 +05:30 committed by Shahidh K Muhammed
parent 300684f2dc
commit 91376316f2
10 changed files with 103 additions and 6 deletions

View File

@ -1,6 +1,6 @@
Name,Aliases,Description,GraphQL Engine Type
bigint,int8,signed eight-byte integer,Int_
bigserial,serial8,autoincrementing eight-byte integer,Int_
bigint,int8,signed eight-byte integer,String_
bigserial,serial8,autoincrementing eight-byte integer,String_
bit [ (n) ],,fixed-length bit string,Implicit_
bit varying [ (n) ],varbit [ (n) ],variable-length bit string,Implicit_
boolean,bool,logical Boolean (true/false),Bool_

1 Name Aliases Description GraphQL Engine Type
2 bigint int8 signed eight-byte integer Int_ String_
3 bigserial serial8 autoincrementing eight-byte integer Int_ String_
4 bit [ (n) ] fixed-length bit string Implicit_
5 bit varying [ (n) ] varbit [ (n) ] variable-length bit string Implicit_
6 boolean bool logical Boolean (true/false) Bool_

View File

@ -233,9 +233,9 @@ mkColExtr (c, pct) =
mkColExtrAl (Just c) (c, pct)
mkColExtrAl :: (IsIden a) => Maybe a -> (PGCol, PGColType) -> S.Extractor
mkColExtrAl alM (c, pct) =
if pct == PGGeometry || pct == PGGeography
then S.mkAliasedExtrFromExp
mkColExtrAl alM (c, pct)
| pct == PGGeometry || pct == PGGeography =
S.mkAliasedExtrFromExp
( S.SEFnApp "ST_AsGeoJSON"
[ S.mkSIdenExp c
, S.SEUnsafe "15" -- max decimal digits
@ -243,7 +243,10 @@ mkColExtrAl alM (c, pct) =
] Nothing
`S.SETyAnn` S.jsonType
) alM
else S.mkAliasedExtr c alM
| pct == PGBigInt || pct == PGBigSerial =
S.mkAliasedExtrFromExp
(S.mkSIdenExp c `S.SETyAnn` S.textType) alM
| otherwise = S.mkAliasedExtr c alM
-- validate headers
validateHeaders :: (P1C m) => [T.Text] -> m ()

View File

@ -0,0 +1,21 @@
description: Simple GraphQL query to fetch items from user table
url: /v1alpha1/graphql
status: 200
response:
data:
user:
- id: '1'
name: User 1
number: '123456789'
- id: '2'
name: User 2
number: '123456780'
query:
query: |
query {
user {
id
name
number
}
}

View File

@ -85,3 +85,24 @@ args:
true
)
#User table with bigserial and bigint columns
- type: run_sql
args:
sql: |
CREATE TABLE "user" (
id BIGSERIAL PRIMARY KEY,
name TEXT NOT NULL,
number BIGINT
);
- type: track_table
args:
schema: public
name: user
- type: insert
args:
table: user
objects:
- name: User 1
number: '123456789'
- name: User 2
number: '123456780'

View File

@ -18,3 +18,7 @@ args:
sql: |
drop table author
- type: run_sql
args:
sql: |
drop table "user"

View File

@ -0,0 +1,17 @@
url: /v1/query
status: 200
response:
- id: '1'
name: User 1
number: '123456789'
- id: '2'
name: User 2
number: '123456780'
query:
type: select
args:
table: user
columns:
- id
- name
- number

View File

@ -83,3 +83,24 @@ args:
true
)
#User table with bigserial and bigint columns
- type: run_sql
args:
sql: |
CREATE TABLE "user" (
id BIGSERIAL PRIMARY KEY,
name TEXT NOT NULL,
number BIGINT
);
- type: track_table
args:
schema: public
name: user
- type: insert
args:
table: user
objects:
- name: User 1
number: '123456789'
- name: User 2
number: '123456780'

View File

@ -16,3 +16,7 @@ args:
args:
sql: |
drop table author
- type: run_sql
args:
sql: |
drop table "user"

View File

@ -19,6 +19,9 @@ class TestGraphQLQueryBasic:
def test_nested_select_query_where(self, hge_ctx):
check_query_f(hge_ctx, self.dir + '/nested_select_where_query_author_article.yaml')
def test_select_query_user(self, hge_ctx):
check_query_f(hge_ctx, "queries/graphql_query/basic/select_query_user.yaml")
@pytest.fixture(autouse=True)
def transact(self, request, hge_ctx):
self.dir = 'queries/graphql_query/basic'

View File

@ -19,6 +19,9 @@ class TestV1SelectBasic:
def test_nested_select_query_where(self, hge_ctx):
check_query_f(hge_ctx, self.dir + '/nested_select_where_query_author_article.yaml')
def test_select_query_user(self, hge_ctx):
check_query_f(hge_ctx, self.dir + '/select_user.yaml')
@pytest.fixture(autouse=True)
def transact(self, request, hge_ctx):
self.dir = "queries/v1/select/basic"