mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-14 17:02:49 +03:00
Fix new hdb_table_info_agg query to fetch column base types
We mostly want to do this to make queries against information_schema tables work, which the console cares about. information_schema tables use types like sql_identifier, which have no corresponding array types defined! Therefore, in order to generate valid queries for _in and _nin conditions, we need to treat them as their base types, instead.
This commit is contained in:
parent
e2eabcd54e
commit
25c5f97de2
@ -463,13 +463,15 @@ CREATE VIEW hdb_catalog.hdb_table_info_agg AS
|
||||
( SELECT jsonb_agg(jsonb_build_object(
|
||||
'name', "column".attname,
|
||||
'position', "column".attnum,
|
||||
'type', "type".typname,
|
||||
'type', coalesce(base_type.typname, "type".typname),
|
||||
'is_nullable', NOT "column".attnotnull,
|
||||
'description', pg_catalog.col_description("table".oid, "column".attnum)
|
||||
)) AS info
|
||||
FROM pg_catalog.pg_attribute "column"
|
||||
LEFT JOIN pg_catalog.pg_type "type"
|
||||
ON "type".oid = "column".atttypid
|
||||
LEFT JOIN pg_catalog.pg_type base_type
|
||||
ON "type".typtype = 'd' AND base_type.oid = "type".typbasetype
|
||||
WHERE "column".attrelid = "table".oid
|
||||
-- columns where attnum <= 0 are special, system-defined columns
|
||||
AND "column".attnum > 0
|
||||
|
@ -38,13 +38,15 @@ CREATE VIEW hdb_catalog.hdb_table_info_agg AS
|
||||
( SELECT jsonb_agg(jsonb_build_object(
|
||||
'name', "column".attname,
|
||||
'position', "column".attnum,
|
||||
'type', "type".typname,
|
||||
'type', coalesce(base_type.typname, "type".typname),
|
||||
'is_nullable', NOT "column".attnotnull,
|
||||
'description', pg_catalog.col_description("table".oid, "column".attnum)
|
||||
)) AS info
|
||||
FROM pg_catalog.pg_attribute "column"
|
||||
LEFT JOIN pg_catalog.pg_type "type"
|
||||
ON "type".oid = "column".atttypid
|
||||
LEFT JOIN pg_catalog.pg_type base_type
|
||||
ON "type".typtype = 'd' AND base_type.oid = "type".typbasetype
|
||||
WHERE "column".attrelid = "table".oid
|
||||
-- columns where attnum <= 0 are special, system-defined columns
|
||||
AND "column".attnum > 0
|
||||
|
@ -0,0 +1,17 @@
|
||||
description: _in boolexp on column of type sql_identifier
|
||||
url: /v1/graphql
|
||||
status: 200
|
||||
response:
|
||||
data:
|
||||
table_with_sql_identifier:
|
||||
- { id: 3, sql_id: two }
|
||||
- { id: 5, sql_id: four }
|
||||
- { id: 7, sql_id: two }
|
||||
query:
|
||||
query: |
|
||||
query {
|
||||
table_with_sql_identifier(where: {sql_id: {_nin: ["one", "three"]}}) {
|
||||
id
|
||||
sql_id
|
||||
}
|
||||
}
|
@ -275,3 +275,14 @@ args:
|
||||
_where:
|
||||
id: X-Hasura-User-Id
|
||||
is_admin: true
|
||||
|
||||
- type: run_sql
|
||||
args:
|
||||
sql: |
|
||||
CREATE TABLE table_with_sql_identifier
|
||||
( id serial PRIMARY KEY
|
||||
, sql_id information_schema.sql_identifier );
|
||||
INSERT INTO table_with_sql_identifier (sql_id)
|
||||
VALUES ('one'), ('one'), ('two'), ('three'), ('four'), ('one'), ('two');
|
||||
- type: track_table
|
||||
args: table_with_sql_identifier
|
||||
|
@ -3,6 +3,7 @@ args:
|
||||
- type: run_sql
|
||||
args:
|
||||
sql: |
|
||||
DROP TABLE table_with_sql_identifier;
|
||||
DROP TABLE article;
|
||||
DROP TABLE author;
|
||||
DROP TABLE city;
|
||||
|
@ -247,6 +247,9 @@ class TestGraphQLQueryBoolExpBasic(DefaultTestSelectQueries):
|
||||
def test_query_account_permission_fail(self, hge_ctx, transport):
|
||||
check_query_f(hge_ctx, self.dir() + '/query_account_permission_fail.yaml', transport)
|
||||
|
||||
def test_in_sql_identifier_array(self, hge_ctx, transport):
|
||||
check_query_f(hge_ctx, self.dir() + '/in_sql_identifier_array.yaml', transport)
|
||||
|
||||
@classmethod
|
||||
def dir(cls):
|
||||
return 'queries/graphql_query/boolexp/basic'
|
||||
|
Loading…
Reference in New Issue
Block a user