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:
paritosh-08 2021-09-06 15:39:37 +05:30 committed by hasura-bot
parent d06dd037be
commit 8c05efb6d9
3 changed files with 38 additions and 1 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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