Skip to content

Commit

Permalink
feat: Enable backend_only mutations by default (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
morgsmccauley authored Jul 11, 2023
1 parent 39c1f76 commit fc4fb7e
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 2 deletions.
74 changes: 74 additions & 0 deletions indexer-js-queue-handler/__snapshots__/hasura-client.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ exports[`HasuraClient adds the specified permissions for the specified roles/tab
{
"args": {
"permission": {
"backend_only": true,
"check": {},
"columns": "*",
"computed_fields": [],
Expand All @@ -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": {
Expand All @@ -59,6 +96,7 @@ exports[`HasuraClient adds the specified permissions for the specified roles/tab
{
"args": {
"permission": {
"backend_only": true,
"check": {},
"columns": "*",
"computed_fields": [],
Expand All @@ -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",
}
Expand Down
4 changes: 3 additions & 1 deletion indexer-js-queue-handler/hasura-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
},
Expand Down
2 changes: 1 addition & 1 deletion indexer-js-queue-handler/hasura-client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit fc4fb7e

Please sign in to comment.