From fc4fb7e76eb81bac45df0969e2eff832e176a8f4 Mon Sep 17 00:00:00 2001 From: Morgan McCauley Date: Wed, 12 Jul 2023 11:37:43 +1200 Subject: [PATCH] feat: Enable `backend_only` mutations by default (#124) --- .../__snapshots__/hasura-client.test.js.snap | 74 +++++++++++++++++++ indexer-js-queue-handler/hasura-client.js | 4 +- .../hasura-client.test.js | 2 +- 3 files changed, 78 insertions(+), 2 deletions(-) diff --git a/indexer-js-queue-handler/__snapshots__/hasura-client.test.js.snap b/indexer-js-queue-handler/__snapshots__/hasura-client.test.js.snap index cd1464589..b93fa6907 100644 --- a/indexer-js-queue-handler/__snapshots__/hasura-client.test.js.snap +++ b/indexer-js-queue-handler/__snapshots__/hasura-client.test.js.snap @@ -24,6 +24,7 @@ exports[`HasuraClient adds the specified permissions for the specified roles/tab { "args": { "permission": { + "backend_only": true, "check": {}, "columns": "*", "computed_fields": [], @@ -38,6 +39,42 @@ exports[`HasuraClient adds the specified permissions for the specified roles/tab }, "type": "pg_create_insert_permission", }, + { + "args": { + "permission": { + "backend_only": true, + "check": {}, + "columns": "*", + "computed_fields": [], + "filter": {}, + }, + "role": "role", + "source": "default", + "table": { + "name": "height", + "schema": "schema", + }, + }, + "type": "pg_create_update_permission", + }, + { + "args": { + "permission": { + "backend_only": true, + "check": {}, + "columns": "*", + "computed_fields": [], + "filter": {}, + }, + "role": "role", + "source": "default", + "table": { + "name": "height", + "schema": "schema", + }, + }, + "type": "pg_create_delete_permission", + }, { "args": { "permission": { @@ -59,6 +96,7 @@ exports[`HasuraClient adds the specified permissions for the specified roles/tab { "args": { "permission": { + "backend_only": true, "check": {}, "columns": "*", "computed_fields": [], @@ -73,6 +111,42 @@ exports[`HasuraClient adds the specified permissions for the specified roles/tab }, "type": "pg_create_insert_permission", }, + { + "args": { + "permission": { + "backend_only": true, + "check": {}, + "columns": "*", + "computed_fields": [], + "filter": {}, + }, + "role": "role", + "source": "default", + "table": { + "name": "width", + "schema": "schema", + }, + }, + "type": "pg_create_update_permission", + }, + { + "args": { + "permission": { + "backend_only": true, + "check": {}, + "columns": "*", + "computed_fields": [], + "filter": {}, + }, + "role": "role", + "source": "default", + "table": { + "name": "width", + "schema": "schema", + }, + }, + "type": "pg_create_delete_permission", + }, ], "type": "bulk", } diff --git a/indexer-js-queue-handler/hasura-client.js b/indexer-js-queue-handler/hasura-client.js index 4723928ff..395614aa1 100644 --- a/indexer-js-queue-handler/hasura-client.js +++ b/indexer-js-queue-handler/hasura-client.js @@ -230,7 +230,9 @@ export default class HasuraClient { check: {}, computed_fields: [], filter: {}, - ...(permission == 'select' && { allow_aggregations: true }) + ...(permission === "select" + ? { allow_aggregations: true } + : { backend_only: true }), }, source: 'default' }, diff --git a/indexer-js-queue-handler/hasura-client.test.js b/indexer-js-queue-handler/hasura-client.test.js index c64e5a173..150f846b9 100644 --- a/indexer-js-queue-handler/hasura-client.test.js +++ b/indexer-js-queue-handler/hasura-client.test.js @@ -114,7 +114,7 @@ describe('HasuraClient', () => { }); const client = new HasuraClient({ fetch }) - await client.addPermissionsToTables('schema', ['height', 'width'], 'role', ['select', 'insert']); + await client.addPermissionsToTables('schema', ['height', 'width'], 'role', ['select', 'insert', 'update', 'delete']); expect(fetch.mock.calls[0][1].headers['X-Hasura-Admin-Secret']).toBe(HASURA_ADMIN_SECRET) expect(JSON.parse(fetch.mock.calls[0][1].body)).toMatchSnapshot();