Skip to content

Commit

Permalink
bq: test table customization features
Browse files Browse the repository at this point in the history
hasura/graphql-engine-mono#2062

Co-authored-by: Rikin Kachhia <54616969+rikinsk@users.noreply.github.com>
GitOrigin-RevId: 5573efd
  • Loading branch information
2 people authored and hasura-bot committed Aug 18, 2021
1 parent 53703a2 commit 2700554
Show file tree
Hide file tree
Showing 13 changed files with 1,158 additions and 143 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -26,6 +26,7 @@
- server: fix for incorrect `__typename` value in nested remote joins with a customized remote schema
- server: fix a bug where some unicode characters in default string values for fields in remote schemas could lead to internal errors
- server: bigquery: implement `_in` and `_nin` operators. (close #7343)
- server: bigquery: custom root names, table names and field names for bigquery are included in tests
- console: fix untracked foreign-key relationships suggestion across schemas
- console: allow resolution of conflicting inherited role permissions
- cli: fix SDL formatting in `actions.graphql`(#7296)
Expand Down
15 changes: 15 additions & 0 deletions docs/graphql/core/api-reference/metadata-api/index.rst
Expand Up @@ -247,6 +247,21 @@ The various types of queries are listed in the following table:
- 1
- Invoke a trigger with custom payload on a Postgres table

* - :ref:`bigquery_track_table <bigquery_track_table>`
- :ref:`bigquery_track_table_args <bigquery_track_table_syntax>`
- 1
- Add a BigQuery table/view with configuration

* - :ref:`bigquery_untrack_table <bigquery_untrack_table>`
- :ref:`bigquery_untrack_table_args <bigquery_untrack_table_syntax>`
- 1
- Remove a BigQuery table/view

* - :ref:`bigquery_set_table_customization <bigquery_set_table_customization>`
- :ref:`bigquery_set_table_customization_args <bigquery_set_table_customization_syntax>`
- 1
- Set table customization of an already tracked BigQuery table

* - :ref:`mssql_add_source <mssql_add_source>`
- :ref:`mssql_add_source_args <mssql_add_source_syntax>`
- 1
Expand Down
243 changes: 243 additions & 0 deletions docs/graphql/core/api-reference/metadata-api/table-view.rst
Expand Up @@ -507,3 +507,246 @@ Args syntax
- false
- :ref:`SourceName <SourceName>`
- Name of the source database of the table (default: ``default``)


.. _bigquery_track_table:

bigquery_track_table
--------------------

``bigquery_track_table`` is used to add a table/view to the GraphQL schema with configuration.
You can customise the root field names.

Add a table/view ``author``:

.. code-block:: http
POST /v1/metadata HTTP/1.1
Content-Type: application/json
X-Hasura-Role: admin
{
"type": "bigquery_track_table",
"args": {
"table": {
"dataset": "hasura",
"name": "author",
},
"source": "default"
}
}
In the case of BigQuery, dataset names are prefixed to table/view names to form
a unique root field name, such that the above example will result in the root
field name being ``hasura_author``.

.. TODO: BIGQUERY_UNSUPPORTED
A table can be tracked with a ``custom name``. This can be useful when a table
name is not GraphQL compliant, like ``Users Address``, or when the admin
wishes to not expose the root fields in terms of the ``dataset + table/view name``.
A ``custom name`` like ``users_address`` will complement the ``"Users
Address"`` table, so that it can be added to the GraphQL schema.
.. code-block:: http
POST /v1/metadata HTTP/1.1
Content-Type: application/json
X-Hasura-Role: admin
{
"type": "bigquery_track_table",
"args": {
"table": {
"dataset": "hasura",
"name": "Author Details"
}
}
}
``writer_info`` will complement the ``"Users Address"`` table, in the
following case.
.. code-block:: http
POST /v1/metadata HTTP/1.1
Content-Type: application/json
X-Hasura-Role: admin
{
"type": "bigquery_track_table",
"args": {
"table": {
"dataset": "hasura",
"name": "Author Details"
},
"configuration": {
"custom_name": "writer_info",
"custom_root_fields": {
"select_aggregate": "writer_info_agg"
}
}
}
}
.. TODO: BIGQUERY_UNSUPPORTED
The GraphQL nodes and typenames that are generated will be according to the
``identifier``. For example, in this case, the nodes generated will be:
- ``users_address``
- ``users_address_aggregate``
or
- ``writer_info``
- ``writer_info_agg``
respectively
.. note::

Hasura GraphQL engine requires the constraint names (if any) of a table to be
`GraphQL compliant <https://spec.graphql.org/June2018/#sec-Names>`__ in order to be able to track it.

.. _bigquery_track_table_syntax:

Args syntax
^^^^^^^^^^^

.. list-table::
:header-rows: 1

* - Key
- Required
- Schema
- Description
* - table
- true
- {"dataset":_, "name":_}
- Name of the table
* - configuration
- false
- :ref:`Table Config <table_config>`
- Configuration for the table/view
* - source
- false
- :ref:`SourceName <SourceName>`
- Name of the source database of the table (default: ``default``)

.. _bigquery_untrack_table:

bigquery_untrack_table
----------------------

``bigquery_untrack_table`` is used to remove a table/view from the GraphQL schema.

Remove a table/view ``author``:

.. code-block:: http
POST /v1/metadata HTTP/1.1
Content-Type: application/json
X-Hasura-Role: admin
{
"type": "bigquery_untrack_table",
"args": {
"table": {
"dataset": "hasura",
"name": "author"
},
"source": "default",
"cascade": true
}
}
.. _bigquery_untrack_table_syntax:

Args syntax
^^^^^^^^^^^

.. list-table::
:header-rows: 1

* - Key
- Required
- Schema
- Description
* - table
- true
- {"dataset":_, "name":_}
- Name of the table
* - cascade
- false
- Boolean
- When set to ``true``, the effect (if possible) is cascaded to any metadata dependent objects (relationships, permissions, templates)
* - source
- false
- :ref:`SourceName <SourceName>`
- Name of the source database of the table (default: ``default``)

.. _bigquery_set_table_customization:

bigquery_set_table_customization
--------------------------------

``bigquery_set_table_customization`` allows you to customize any given table with
a custom name, custom root fields and custom column names of an already tracked
table. This will **replace** the already present customization.

Set the configuration for a table/view called ``hasura_author_details`` to ``author``:

.. code-block:: http
POST /v1/metadata HTTP/1.1
Content-Type: application/json
X-Hasura-Role: admin
{
"type": "bigquery_set_table_customization",
"args": {
"table": {
"dataset": "hasura",
"name": "author_details",
},
"source": "default",
"configuration": {
"custom_name": "author",
"custom_root_fields": {
"select": "Authors",
"select_aggregate": "AuthorAggregate",
},
"custom_column_names": {
"id": "authorId"
}
}
}
}
.. _bigquery_set_table_customization_syntax:

Args syntax
^^^^^^^^^^^

.. list-table::
:header-rows: 1

* - Key
- Required
- Schema
- Description
* - table
- true
- {"dataset":_, "name":_}
- Name of the table
* - configuration
- false
- :ref:`TableConfig <table_config>`
- Configuration for the table/view
* - source
- false
- :ref:`SourceName <SourceName>`
- Name of the source database of the table (default: ``default``)
1 change: 1 addition & 0 deletions docs/graphql/core/databases/bigquery/index.rst
Expand Up @@ -55,6 +55,7 @@ Know more
:titlesonly:

Getting Started <getting-started>
Schema <schema/index>

.. TODO: DB-COMPATIBILITY
Expand Down

0 comments on commit 2700554

Please sign in to comment.