Skip to content

Commit a6450e1

Browse files
committed
[skip ci] fix introspection query if any enum column present in primary key (fix hasura#5200) (hasura#5522)
1 parent 3868f69 commit a6450e1

File tree

5 files changed

+85
-0
lines changed

5 files changed

+85
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ If you do have such headers configured, then you must update the header configur
1313

1414
(Add entries here in the order of: server, console, cli, docs, others)
1515

16+
- server: fix failing introspection query when an enum column is part of a primary key (fixes #5200)
1617
- server: disallow headers from env variables starting with `HASURA_GRAPHQL_` in actions, event triggers & remote schemas (#5519)
1718
**WARNING**: This might break certain deployments. See `Breaking change` section above.
1819
- server: bugfix to allow HASURA_GRAPHQL_QUERY_PLAN_CACHE_SIZE of 0 (#5363)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# https://github.com/hasura/graphql-engine/issues/5200
2+
description: Test introspecting enum types as user role
3+
url: /v1/graphql
4+
status: 200
5+
headers:
6+
X-Hasura-Role: user
7+
response:
8+
data:
9+
country:
10+
kind: ENUM
11+
name: country_enum
12+
enumValues:
13+
- name: India
14+
description: Republic of India
15+
- name: USA
16+
description: United States of America
17+
zones:
18+
fields:
19+
- name: code
20+
type:
21+
ofType:
22+
name: String
23+
- name: id
24+
type:
25+
ofType:
26+
name: Int
27+
query:
28+
query: |
29+
{
30+
country: __type(name: "country_enum") {
31+
name
32+
kind
33+
enumValues {
34+
name
35+
description
36+
}
37+
}
38+
zones: __type(name: "zones") {
39+
fields {
40+
name
41+
type {
42+
ofType {
43+
name
44+
}
45+
}
46+
}
47+
}
48+
}

server/tests-py/queries/graphql_query/enums/setup.yaml

+31
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,34 @@ args:
2323
('Alyssa', 'red'),
2424
('Ben', 'blue');
2525
26+
CREATE TABLE country
27+
( value text PRIMARY KEY
28+
, comment text);
29+
INSERT INTO country (value, comment) VALUES
30+
('India', 'Republic of India'),
31+
('USA', 'United States of America');
32+
33+
CREATE TABLE zones
34+
( id SERIAL
35+
, code text NOT NULL
36+
, country text NOT NULL REFERENCES country
37+
, PRIMARY KEY (code, country) );
38+
INSERT INTO zones (code, country) VALUES
39+
('67432', 'USA'),
40+
('600036', 'India');
41+
2642
- type: track_table
2743
args:
2844
table: colors
2945
is_enum: true
3046
- type: track_table
3147
args: users
48+
- type: track_table
49+
args:
50+
table: country
51+
is_enum: true
52+
- type: track_table
53+
args: zones
3254

3355
# Anonymous users can query users, but not colors
3456
- type: create_select_permission
@@ -38,3 +60,12 @@ args:
3860
permission:
3961
columns: [id, name, favorite_color]
4062
filter: {}
63+
64+
# A user can query only code but not country
65+
- type: create_select_permission
66+
args:
67+
table: zones
68+
role: user
69+
permission:
70+
columns: [id, code]
71+
filter: {}

server/tests-py/queries/graphql_query/enums/teardown.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ args:
55
sql: |
66
DROP TABLE users;
77
DROP TABLE colors;
8+
DROP TABLE zones;
9+
DROP TABLE country;
810
cascade: true

server/tests-py/test_graphql_queries.py

+3
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,9 @@ def dir(cls):
564564
def test_introspect(self, hge_ctx, transport):
565565
check_query_f(hge_ctx, self.dir() + '/introspect.yaml', transport)
566566

567+
def test_introspect_user_role(self, hge_ctx, transport):
568+
check_query_f(hge_ctx, self.dir() + '/introspect_user_role.yaml', transport)
569+
567570
def test_select_enum_field(self, hge_ctx, transport):
568571
check_query_f(hge_ctx, self.dir() + '/select_enum_field.yaml', transport)
569572

0 commit comments

Comments
 (0)