mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-14 08:02:15 +03:00
server: disable mutation for materialised views
The materialized views cannot be mutated, so this commit removes the option to run mutation on the materialized views via graphql endpoint. Before this, users could have tried running mutation for the materialized views using the graphql endpoint (or from HGE console), which would have resulted in the following error: ``` JSON { "errors": [ { "extensions": { "internal": { "statement": "WITH \"articles_mat_view__mutation_result_alias\" AS (DELETE FROM \"public\".\"articles_mat_view\" WHERE (('true') AND (((((\"public\".\"articles_mat_view\".\"id\") = (('20155721-961c-4d8b-a5c4-873ed62c7a61')::uuid)) AND ('true')) AND ('true')) AND ('true'))) RETURNING * ), \"articles_mat_view__all_columns_alias\" AS (SELECT \"id\" , \"author_id\" , \"content\" , \"test_col\" , \"test_col2\" FROM \"articles_mat_view__mutation_result_alias\" ) SELECT json_build_object('affected_rows', (SELECT COUNT(*) FROM \"articles_mat_view__all_columns_alias\" ) ) ", "prepared": false, "error": { "exec_status": "FatalError", "hint": null, "message": "cannot change materialized view \"articles_mat_view\"", "status_code": "42809", "description": null }, "arguments": [] }, "path": "$", "code": "unexpected" }, "message": "database query error" } ] } ``` So, we don't want to generate the mutation fields for the materialized views altogether. https://github.com/hasura/graphql-engine-mono/pull/2226 GitOrigin-RevId: 4ef441764035a8039e1c780d454569ee1f2febc3
This commit is contained in:
parent
d06dd037be
commit
8c05efb6d9
@ -4,6 +4,7 @@
|
||||
|
||||
(Add entries below in the order of server, console, cli, docs, others)
|
||||
|
||||
- server: disable mutation for materialised views (#6688)
|
||||
- server: set `tracecontext` and `userInfo` for DML actions on Postgres sources
|
||||
- cli: add progress bar for `migrate apply` command (#4795)
|
||||
|
||||
|
@ -10,7 +10,9 @@ SELECT
|
||||
-- Note: unique_constraints does NOT include primary key constraints!
|
||||
'unique_constraints', coalesce(unique_constraints.info, '[]'),
|
||||
'foreign_keys', coalesce(foreign_key_constraints.info, '[]'),
|
||||
'view_info', CASE "table".relkind WHEN 'v' THEN jsonb_build_object(
|
||||
-- Note: for views and materialized views, we are asking Postgres if it is mutable or not
|
||||
-- and for any other case, we are assuming it to be mutable.
|
||||
'view_info', CASE WHEN "table".relkind IN ('v', 'm') THEN jsonb_build_object(
|
||||
'is_updatable', ((pg_catalog.pg_relation_is_updatable("table".oid, true) & 4) = 4),
|
||||
'is_insertable', ((pg_catalog.pg_relation_is_updatable("table".oid, true) & 8) = 8),
|
||||
'is_deletable', ((pg_catalog.pg_relation_is_updatable("table".oid, true) & 16) = 16)
|
||||
|
@ -38,6 +38,40 @@
|
||||
- title
|
||||
- name
|
||||
|
||||
# Introspecting the GraphQL schema for query field for the materialized view
|
||||
- description: Checking query fields by introspection
|
||||
url: /v1/graphql
|
||||
status: 200
|
||||
response:
|
||||
data:
|
||||
__type:
|
||||
name: "articles"
|
||||
query:
|
||||
query: "query checkQuery {__type(name:\"articles\"){name}}"
|
||||
|
||||
# Test for checking if the mutation field doesn't exist for the materialized view
|
||||
- description: Checking mutation fields for materialized view
|
||||
url: /v1/graphql
|
||||
status: 200
|
||||
response:
|
||||
errors:
|
||||
- extensions:
|
||||
path: "$"
|
||||
code: "validation-failed"
|
||||
message: "no mutations exist"
|
||||
query:
|
||||
query: "mutation MyMutation { delete_articles(where: {title: {_eq: \"Lorem ipsum dolor sit amet\"}}) { affected_rows }}"
|
||||
|
||||
# Introspecting the GraphQL schema for mutation fields for the materialized view
|
||||
- description: Checking mutation fields by introspection
|
||||
url: /v1/graphql
|
||||
status: 200
|
||||
response:
|
||||
data:
|
||||
__type: null
|
||||
query:
|
||||
query: "query checkMutation {__type(name:\"articles_insert_input\"){name}}"
|
||||
|
||||
- description: Untrack materialized view
|
||||
url: /v1/query
|
||||
status: 200
|
||||
|
Loading…
Reference in New Issue
Block a user