Graphql-engine: Unable to hide columns, also unable to alias table names

Created on 9 Apr 2020  路  5Comments  路  Source: hasura/graphql-engine

Hello folks,

I am trialing Hasura on a legacy database.

Current server version: v1.1.1
Latest stable server version: v1.1.1
Console asset version: 1585320727535

I have a constraint that I cannot make any schema changes

I would love to learn if there is an option for me to use Hasura to achieve the following

  1. Ability to hide columns from appearing in the schema
    When I track a table all the columns in the table becomes available in the GraphQL schema.
    Some of the columns store ids to foreign tables which is already factored in by foreign key relationships, I would like to hide those columns to have a clean Graphql type

  2. Rename tables
    Some of the tables have cryptic names that are not understandable by the consumer of the GraphQL schema, I want to rename them in the GraphQL Schema

Thanks,
Soney

question

Most helpful comment

Does it avoid it from appearing in schema anymore?

Yes, if you using the role (by providing x-hasura-role header, say), then only part of the schema which has permission to will appear. Hasura has Role Based Schemas: https://hasura.io/docs/1.0/graphql/manual/auth/authorization/roles-variables.html#roles

What I wanted to do is Table name renaming instead of Field name renaming :)

Ah, not yet but very soon: https://github.com/hasura/graphql-engine/issues/3811

But as @GavinRay97 showed above, you can also manually change the names for each of the field that uses the table name.

All 5 comments

Hi @soneymathew

  1. You can definitely do this. You can create a role, say user, and uncheck the columns you want to hide in the select permissions: https://hasura.io/docs/1.0/graphql/manual/auth/authorization/permission-rules.html#column-level-permissions

(We are also thinking about global permissions which would let you configure this automatically for all roles essentially: https://github.com/hasura/graphql-engine/issues/280)

  1. You can do this too: https://hasura.io/docs/1.0/graphql/manual/schema/custom-field-names.html#custom-field-names

Thanks @tirumaraiselvan

  1. Does it avoid it from appearing in schema anymore?

  2. What I wanted to do is Table name renaming instead of Field name renaming :)

You can use "Custom GraphQL Root Fields" feature in the table modification tab to change the table name values in the schema:

image

After changing user resolver for select to new_user_name:

image

Does this help?

Does it avoid it from appearing in schema anymore?

Yes, if you using the role (by providing x-hasura-role header, say), then only part of the schema which has permission to will appear. Hasura has Role Based Schemas: https://hasura.io/docs/1.0/graphql/manual/auth/authorization/roles-variables.html#roles

What I wanted to do is Table name renaming instead of Field name renaming :)

Ah, not yet but very soon: https://github.com/hasura/graphql-engine/issues/3811

But as @GavinRay97 showed above, you can also manually change the names for each of the field that uses the table name.

Thanks for the guidance @tirumaraiselvan / @GavinRay97 馃檹
I will follow #3811 for updates.

Was this page helpful?
0 / 5 - 0 ratings