Skip to content

Commit

Permalink
[skip ci] fix introspection query if any enum column present in prima…
Browse files Browse the repository at this point in the history
…ry key (fix hasura#5200) (hasura#5522)
  • Loading branch information
rakeshkky committed Aug 6, 2020
1 parent 3868f69 commit a6450e1
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ If you do have such headers configured, then you must update the header configur

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

- server: fix failing introspection query when an enum column is part of a primary key (fixes #5200)
- server: disallow headers from env variables starting with `HASURA_GRAPHQL_` in actions, event triggers & remote schemas (#5519)
**WARNING**: This might break certain deployments. See `Breaking change` section above.
- server: bugfix to allow HASURA_GRAPHQL_QUERY_PLAN_CACHE_SIZE of 0 (#5363)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# https://github.com/hasura/graphql-engine/issues/5200
description: Test introspecting enum types as user role
url: /v1/graphql
status: 200
headers:
X-Hasura-Role: user
response:
data:
country:
kind: ENUM
name: country_enum
enumValues:
- name: India
description: Republic of India
- name: USA
description: United States of America
zones:
fields:
- name: code
type:
ofType:
name: String
- name: id
type:
ofType:
name: Int
query:
query: |
{
country: __type(name: "country_enum") {
name
kind
enumValues {
name
description
}
}
zones: __type(name: "zones") {
fields {
name
type {
ofType {
name
}
}
}
}
}
31 changes: 31 additions & 0 deletions server/tests-py/queries/graphql_query/enums/setup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,34 @@ args:
('Alyssa', 'red'),
('Ben', 'blue');
CREATE TABLE country
( value text PRIMARY KEY
, comment text);
INSERT INTO country (value, comment) VALUES
('India', 'Republic of India'),
('USA', 'United States of America');
CREATE TABLE zones
( id SERIAL
, code text NOT NULL
, country text NOT NULL REFERENCES country
, PRIMARY KEY (code, country) );
INSERT INTO zones (code, country) VALUES
('67432', 'USA'),
('600036', 'India');
- type: track_table
args:
table: colors
is_enum: true
- type: track_table
args: users
- type: track_table
args:
table: country
is_enum: true
- type: track_table
args: zones

# Anonymous users can query users, but not colors
- type: create_select_permission
Expand All @@ -38,3 +60,12 @@ args:
permission:
columns: [id, name, favorite_color]
filter: {}

# A user can query only code but not country
- type: create_select_permission
args:
table: zones
role: user
permission:
columns: [id, code]
filter: {}
2 changes: 2 additions & 0 deletions server/tests-py/queries/graphql_query/enums/teardown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ args:
sql: |
DROP TABLE users;
DROP TABLE colors;
DROP TABLE zones;
DROP TABLE country;
cascade: true
3 changes: 3 additions & 0 deletions server/tests-py/test_graphql_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,9 @@ def dir(cls):
def test_introspect(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/introspect.yaml', transport)

def test_introspect_user_role(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/introspect_user_role.yaml', transport)

def test_select_enum_field(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_enum_field.yaml', transport)

Expand Down

0 comments on commit a6450e1

Please sign in to comment.