MS SQL Server: Customise auto-generated field names¶
Table of contents
Introduction¶
Hasura auto-generates GraphQL field names based on your database table and column names. If you’d like to change the defaults, it is possible to override and rename the auto-generated table and column field names exposed over the GraphQL API.
Supported from
This feature is supported in versions v1.0.0-beta.8
and later.
Expose columns with a different name in the GraphQL API¶
You can customize auto-generated field names in the tables.yaml
file inside the metadata
directory:
- table:
schema: dbo
name: author
configuration:
custom_column_names:
addr: address
Apply the metadata by running:
hasura metadata apply
A custom field name can be set for a column via the following 2 methods:
Passing a Table Config with the CustomColumnNames to the mssql_set_table_customization API while tracking a table:
POST /v1/metadata HTTP/1.1 Content-Type: application/json X-Hasura-Role: admin { "type": "mssql_set_table_customization", "args": { "table": "authors", "configuration": { "custom_column_names": { "id": "AuthorId" } } } }
Customization can be done at the time of creation using mssql_track_table API also.
Expose table root fields with a different name in the GraphQL API¶
You can expose table root fields with a different name in the GraphQL API in the tables.yaml
file inside the metadata
directory:
- table:
schema: dbo
name: authors
configuration:
custom_root_fields:
select: authors_aggregate
After that, apply the metadata by running:
hasura metadata apply
A custom field name can be set for a table root field via the following 2 methods:
Passing a Table Config with the Custom Root Fields to the mssql_set_table_customization API while tracking a table:
POST /v1/metadata HTTP/1.1 Content-Type: application/json X-Hasura-Role: admin { "type": "mssql_set_table_customization", "args": { "table": "authors", "configuration": { "custom_column_names": { "id": "AuthorId" } "custom_root_fields": { "select": "authors", "select_aggregate": "authors_aggregate" } } } }
Customization can be done at the time of creation using mssql_track_table API also.