2019-03-28 13:51:58 +03:00
|
|
|
.. _metadata_apis:
|
|
|
|
|
2019-02-06 09:39:36 +03:00
|
|
|
Schema / Metadata API Reference
|
|
|
|
===============================
|
2018-10-08 17:12:03 +03:00
|
|
|
|
2018-12-03 15:12:24 +03:00
|
|
|
.. contents:: Table of contents
|
|
|
|
:backlinks: none
|
|
|
|
:depth: 1
|
|
|
|
:local:
|
|
|
|
|
2019-09-11 10:17:14 +03:00
|
|
|
The schema / metadata API provides the following features:
|
2018-10-08 17:12:03 +03:00
|
|
|
|
|
|
|
1. Execute SQL on the underlying Postgres database, supports schema modifying actions.
|
2019-09-11 10:17:14 +03:00
|
|
|
2. Modify Hasura metadata (permission rules and relationships).
|
2018-10-08 17:12:03 +03:00
|
|
|
|
2019-09-11 10:17:14 +03:00
|
|
|
This is primarily intended to be used as an ``admin`` API to manage the Hasura schema and metadata.
|
2018-10-08 17:12:03 +03:00
|
|
|
|
|
|
|
Endpoint
|
|
|
|
--------
|
|
|
|
|
|
|
|
All requests are ``POST`` requests to the ``/v1/query`` endpoint.
|
|
|
|
|
2018-12-03 15:12:24 +03:00
|
|
|
Request structure
|
|
|
|
-----------------
|
2018-10-08 17:12:03 +03:00
|
|
|
|
|
|
|
.. code-block:: http
|
|
|
|
|
|
|
|
POST /v1/query HTTP/1.1
|
|
|
|
|
|
|
|
{
|
2018-10-29 12:12:44 +03:00
|
|
|
"type": "<query-type>",
|
2018-10-08 17:12:03 +03:00
|
|
|
"args": <args-object>
|
|
|
|
}
|
|
|
|
|
2019-02-06 09:39:36 +03:00
|
|
|
Request body
|
|
|
|
^^^^^^^^^^^^
|
2018-10-08 17:12:03 +03:00
|
|
|
|
2019-02-06 09:39:36 +03:00
|
|
|
.. parsed-literal::
|
2018-10-08 17:12:03 +03:00
|
|
|
|
2019-02-06 09:39:36 +03:00
|
|
|
Query_
|
|
|
|
|
|
|
|
.. _Query:
|
|
|
|
|
|
|
|
Query
|
|
|
|
*****
|
2018-10-08 17:12:03 +03:00
|
|
|
|
|
|
|
.. list-table::
|
|
|
|
:header-rows: 1
|
|
|
|
|
|
|
|
* - Key
|
|
|
|
- Required
|
|
|
|
- Schema
|
|
|
|
- Description
|
|
|
|
* - type
|
|
|
|
- true
|
|
|
|
- String
|
|
|
|
- Type of the query
|
|
|
|
* - args
|
|
|
|
- true
|
|
|
|
- JSON Value
|
|
|
|
- The arguments to the query
|
2019-09-19 07:47:36 +03:00
|
|
|
* - version
|
|
|
|
- false
|
|
|
|
- Integer
|
|
|
|
- Version of the API (default: 1)
|
2018-10-08 17:12:03 +03:00
|
|
|
|
2019-05-13 12:41:07 +03:00
|
|
|
Request types
|
|
|
|
-------------
|
|
|
|
|
2018-10-08 17:12:03 +03:00
|
|
|
The various types of queries are listed in the following table:
|
|
|
|
|
|
|
|
.. list-table::
|
|
|
|
:header-rows: 1
|
|
|
|
|
|
|
|
* - ``type``
|
|
|
|
- ``args``
|
2019-09-19 07:47:36 +03:00
|
|
|
- ``version``
|
2019-02-06 09:39:36 +03:00
|
|
|
- Synopsis
|
|
|
|
|
|
|
|
* - **bulk**
|
|
|
|
- :ref:`Query <Query>` array
|
2019-09-19 07:47:36 +03:00
|
|
|
- 1
|
2019-02-06 09:39:36 +03:00
|
|
|
- Execute multiple operations in a single query
|
2018-10-08 17:12:03 +03:00
|
|
|
|
|
|
|
* - :ref:`run_sql`
|
|
|
|
- :ref:`run_sql_args <run_sql_syntax>`
|
2019-09-19 07:47:36 +03:00
|
|
|
- 1
|
2018-10-08 17:12:03 +03:00
|
|
|
- Run SQL directly on Postgres
|
|
|
|
|
2018-10-17 08:27:11 +03:00
|
|
|
* - :ref:`track_table`
|
|
|
|
- :ref:`TableName <TableName>`
|
2019-09-19 07:47:36 +03:00
|
|
|
- 1
|
2018-10-17 08:27:11 +03:00
|
|
|
- Add a table/view
|
|
|
|
|
2019-09-19 07:47:36 +03:00
|
|
|
* - :ref:`track_table <track_table_v2>`
|
|
|
|
- :ref:`track_table_args <track_table_args_syntax_v2>`
|
|
|
|
- 2
|
|
|
|
- Add a table/view with configuration
|
|
|
|
|
|
|
|
* - :ref:`set_table_custom_fields <set_table_custom_fields>`
|
|
|
|
- :ref:`set_table_custom_fields_args <set_table_custom_fields_args_syntax>`
|
|
|
|
- 2
|
|
|
|
- Set custom fields to an already tracked table
|
|
|
|
|
2018-10-17 08:27:11 +03:00
|
|
|
* - :ref:`untrack_table`
|
|
|
|
- :ref:`untrack_table_args <untrack_table_syntax>`
|
2019-09-19 07:47:36 +03:00
|
|
|
- 1
|
2018-10-17 08:27:11 +03:00
|
|
|
- Remove a table/view
|
|
|
|
|
2019-01-25 06:31:54 +03:00
|
|
|
* - :ref:`track_function`
|
|
|
|
- :ref:`FunctionName <FunctionName>`
|
2019-09-19 07:47:36 +03:00
|
|
|
- 1
|
2019-09-11 10:17:14 +03:00
|
|
|
- Add an SQL function
|
2019-01-25 06:31:54 +03:00
|
|
|
|
|
|
|
* - :ref:`untrack_function`
|
|
|
|
- :ref:`FunctionName <FunctionName>`
|
2019-09-19 07:47:36 +03:00
|
|
|
- 1
|
2019-09-11 10:17:14 +03:00
|
|
|
- Remove an SQL function
|
2019-01-25 06:31:54 +03:00
|
|
|
|
2018-10-08 17:12:03 +03:00
|
|
|
* - :ref:`create_object_relationship`
|
|
|
|
- :ref:`create_object_relationship_args <create_object_relationship_syntax>`
|
2019-09-19 07:47:36 +03:00
|
|
|
- 1
|
2018-10-08 17:12:03 +03:00
|
|
|
- Define a new object relationship
|
|
|
|
|
|
|
|
* - :ref:`create_array_relationship`
|
|
|
|
- :ref:`create_array_relationship_args <create_array_relationship_syntax>`
|
2019-09-19 07:47:36 +03:00
|
|
|
- 1
|
2018-10-08 17:12:03 +03:00
|
|
|
- Define a new array relationship
|
|
|
|
|
|
|
|
* - :ref:`drop_relationship`
|
|
|
|
- :ref:`drop_relationship_args <drop_relationship_syntax>`
|
2019-09-19 07:47:36 +03:00
|
|
|
- 1
|
2018-10-08 17:12:03 +03:00
|
|
|
- Drop an existing relationship
|
|
|
|
|
|
|
|
* - :ref:`set_relationship_comment`
|
|
|
|
- :ref:`set_relationship_comment_args <set_relationship_comment_syntax>`
|
2019-09-19 07:47:36 +03:00
|
|
|
- 1
|
2018-10-08 17:12:03 +03:00
|
|
|
- Set comment on an existing relationship
|
|
|
|
|
2019-10-18 11:29:47 +03:00
|
|
|
* - :ref:`add_computed_field`
|
|
|
|
- :ref:`add_computed_field_args <add_computed_field_syntax>`
|
|
|
|
- 1
|
|
|
|
- Add a computed field
|
|
|
|
|
|
|
|
* - :ref:`drop_computed_field`
|
|
|
|
- :ref:`drop_computed_field_args <drop_computed_field_syntax>`
|
|
|
|
- 1
|
|
|
|
- Drop a computed field
|
|
|
|
|
2018-10-08 17:12:03 +03:00
|
|
|
* - :ref:`create_insert_permission`
|
|
|
|
- :ref:`create_insert_permission_args <create_insert_permission_syntax>`
|
2019-09-19 07:47:36 +03:00
|
|
|
- 1
|
2018-10-08 17:12:03 +03:00
|
|
|
- Specify insert permission
|
|
|
|
|
|
|
|
* - :ref:`drop_insert_permission`
|
|
|
|
- :ref:`drop_insert_permission_args <drop_insert_permission_syntax>`
|
2019-09-19 07:47:36 +03:00
|
|
|
- 1
|
2018-10-08 17:12:03 +03:00
|
|
|
- Remove existing insert permission
|
|
|
|
|
|
|
|
* - :ref:`create_select_permission`
|
|
|
|
- :ref:`create_select_permission_args <create_select_permission_syntax>`
|
2019-09-19 07:47:36 +03:00
|
|
|
- 1
|
2018-10-08 17:12:03 +03:00
|
|
|
- Specify select permission
|
|
|
|
|
|
|
|
* - :ref:`drop_select_permission`
|
|
|
|
- :ref:`drop_select_permission_args <drop_select_permission_syntax>`
|
2019-09-19 07:47:36 +03:00
|
|
|
- 1
|
2018-10-08 17:12:03 +03:00
|
|
|
- Remove existing select permission
|
|
|
|
|
|
|
|
* - :ref:`create_update_permission`
|
|
|
|
- :ref:`create_update_permission_args <create_update_permission_syntax>`
|
2019-09-19 07:47:36 +03:00
|
|
|
- 1
|
2018-10-08 17:12:03 +03:00
|
|
|
- Specify update permission
|
|
|
|
|
|
|
|
* - :ref:`drop_update_permission`
|
|
|
|
- :ref:`drop_update_permission_args <drop_update_permission_syntax>`
|
2019-09-19 07:47:36 +03:00
|
|
|
- 1
|
2018-10-08 17:12:03 +03:00
|
|
|
- Remove existing update permission
|
|
|
|
|
|
|
|
* - :ref:`create_delete_permission`
|
|
|
|
- :ref:`create_delete_permission_args <create_delete_permission_syntax>`
|
2019-09-19 07:47:36 +03:00
|
|
|
- 1
|
2018-10-08 17:12:03 +03:00
|
|
|
- Specify delete permission
|
|
|
|
|
|
|
|
* - :ref:`drop_delete_permission`
|
|
|
|
- :ref:`drop_delete_permission_args <drop_delete_permission_syntax>`
|
2019-09-19 07:47:36 +03:00
|
|
|
- 1
|
2018-10-08 17:12:03 +03:00
|
|
|
- Remove existing delete permission
|
|
|
|
|
|
|
|
* - :ref:`set_permission_comment`
|
|
|
|
- :ref:`set_permission_comment_args <set_permission_comment_syntax>`
|
2019-09-19 07:47:36 +03:00
|
|
|
- 1
|
2018-10-08 17:12:03 +03:00
|
|
|
- Set comment on an existing permission
|
|
|
|
|
2018-10-25 10:22:51 +03:00
|
|
|
* - :ref:`create_event_trigger`
|
|
|
|
- :ref:`create_event_trigger_args <create_event_trigger_syntax>`
|
2019-09-19 07:47:36 +03:00
|
|
|
- 1
|
2019-09-11 10:17:14 +03:00
|
|
|
- Create or replace an event trigger
|
2019-07-08 08:51:41 +03:00
|
|
|
|
2019-09-11 10:17:14 +03:00
|
|
|
* - :ref:`invoke_event_trigger`
|
|
|
|
- :ref:`invoke_event_trigger_args <invoke_event_trigger_syntax>`
|
2019-09-19 07:47:36 +03:00
|
|
|
- 1
|
2019-09-11 10:17:14 +03:00
|
|
|
- Invoke a trigger manually
|
2019-05-13 12:41:07 +03:00
|
|
|
|
2019-09-19 07:47:36 +03:00
|
|
|
* - :ref:`delete_event_trigger`
|
|
|
|
- :ref:`delete_event_trigger_args <delete_event_trigger_syntax>`
|
|
|
|
- 1
|
|
|
|
- Delete an existing event trigger
|
|
|
|
|
2019-07-08 08:51:41 +03:00
|
|
|
* - :ref:`add_remote_schema`
|
|
|
|
- :ref:`add_remote_schema_args <add_remote_schema_syntax>`
|
2019-09-19 07:47:36 +03:00
|
|
|
- 1
|
2019-09-11 10:17:14 +03:00
|
|
|
- Add a remote GraphQL server as a remote schema
|
2019-07-08 08:51:41 +03:00
|
|
|
|
|
|
|
* - :ref:`remove_remote_schema`
|
|
|
|
- :ref:`remove_remote_schema_args <remove_remote_schema_syntax>`
|
2019-09-19 07:47:36 +03:00
|
|
|
- 1
|
2019-09-11 10:17:14 +03:00
|
|
|
- Remove an existing remote schema
|
2019-07-08 08:51:41 +03:00
|
|
|
|
|
|
|
* - :ref:`reload_remote_schema`
|
|
|
|
- :ref:`reload_remote_schema_args <reload_remote_schema_syntax>`
|
2019-09-19 07:47:36 +03:00
|
|
|
- 1
|
2019-09-11 10:17:14 +03:00
|
|
|
- Reload schema of an existing remote schema
|
2019-05-16 09:13:25 +03:00
|
|
|
|
2019-03-28 13:51:58 +03:00
|
|
|
* - :ref:`export_metadata`
|
2019-04-17 19:29:39 +03:00
|
|
|
- :ref:`Empty Object`
|
2019-09-19 07:47:36 +03:00
|
|
|
- 1
|
2019-03-28 13:51:58 +03:00
|
|
|
- Export the current metadata
|
|
|
|
|
|
|
|
* - :ref:`replace_metadata`
|
|
|
|
- :ref:`replace_metadata_args <replace_metadata_syntax>`
|
2019-09-19 07:47:36 +03:00
|
|
|
- 1
|
2019-03-28 13:51:58 +03:00
|
|
|
- Import and replace existing metadata
|
|
|
|
|
|
|
|
* - :ref:`reload_metadata`
|
2019-04-17 19:29:39 +03:00
|
|
|
- :ref:`Empty Object`
|
2019-09-19 07:47:36 +03:00
|
|
|
- 1
|
2019-03-28 13:51:58 +03:00
|
|
|
- Reload changes to the underlying Postgres DB
|
|
|
|
|
|
|
|
* - :ref:`clear_metadata`
|
2019-04-17 19:29:39 +03:00
|
|
|
- :ref:`Empty Object`
|
2019-09-19 07:47:36 +03:00
|
|
|
- 1
|
2019-03-28 13:51:58 +03:00
|
|
|
- Clear/wipe-out the current metadata state form server
|
|
|
|
|
2019-04-17 19:29:39 +03:00
|
|
|
* - :ref:`get_inconsistent_metadata`
|
|
|
|
- :ref:`Empty Object`
|
2019-09-19 07:47:36 +03:00
|
|
|
- 1
|
2019-04-17 19:29:39 +03:00
|
|
|
- List all inconsistent metadata objects
|
2019-05-16 09:13:25 +03:00
|
|
|
|
2019-04-17 19:29:39 +03:00
|
|
|
* - :ref:`drop_inconsistent_metadata`
|
|
|
|
- :ref:`Empty Object`
|
2019-09-19 07:47:36 +03:00
|
|
|
- 1
|
2019-04-17 19:29:39 +03:00
|
|
|
- Drop all inconsistent metadata objects
|
|
|
|
|
2019-05-16 09:13:25 +03:00
|
|
|
* - :ref:`create_query_collection`
|
|
|
|
- :ref:`create_query_collection_args <create_query_collection_syntax>`
|
2019-09-19 07:47:36 +03:00
|
|
|
- 1
|
2019-05-16 09:13:25 +03:00
|
|
|
- Create a query collection
|
|
|
|
|
|
|
|
* - :ref:`drop_query_collection`
|
|
|
|
- :ref:`drop_query_collection_args <drop_query_collection_syntax>`
|
2019-09-19 07:47:36 +03:00
|
|
|
- 1
|
2019-05-16 09:13:25 +03:00
|
|
|
- Drop a query collection
|
|
|
|
|
|
|
|
* - :ref:`add_query_to_collection`
|
|
|
|
- :ref:`add_query_to_collection_args <add_query_to_collection_syntax>`
|
2019-09-19 07:47:36 +03:00
|
|
|
- 1
|
2019-09-11 10:17:14 +03:00
|
|
|
- Add a query to a given collection
|
2019-05-16 09:13:25 +03:00
|
|
|
|
|
|
|
* - :ref:`drop_query_from_collection`
|
|
|
|
- :ref:`drop_query_from_collection_args <drop_query_from_collection_syntax>`
|
2019-09-19 07:47:36 +03:00
|
|
|
- 1
|
2019-09-11 10:17:14 +03:00
|
|
|
- Drop a query from a given collection
|
2019-05-16 09:13:25 +03:00
|
|
|
|
|
|
|
* - :ref:`add_collection_to_allowlist`
|
|
|
|
- :ref:`add_collection_to_allowlist_args <add_collection_to_allowlist_syntax>`
|
2019-09-19 07:47:36 +03:00
|
|
|
- 1
|
2019-09-11 10:17:14 +03:00
|
|
|
- Add a collection to the allow-list
|
2019-05-16 09:13:25 +03:00
|
|
|
|
|
|
|
* - :ref:`drop_collection_from_allowlist`
|
|
|
|
- :ref:`drop_collection_from_allowlist_args <drop_collection_from_allowlist_syntax>`
|
2019-09-19 07:47:36 +03:00
|
|
|
- 1
|
2019-09-11 10:17:14 +03:00
|
|
|
- Drop a collection from the allow-list
|
2019-04-17 19:29:39 +03:00
|
|
|
|
2018-12-03 15:12:24 +03:00
|
|
|
**See:**
|
2018-10-08 17:12:03 +03:00
|
|
|
|
|
|
|
- :doc:`Run SQL <run-sql>`
|
2018-10-17 08:27:11 +03:00
|
|
|
- :doc:`Tables/Views <table-view>`
|
2019-01-25 06:31:54 +03:00
|
|
|
- :doc:`Custom SQL Functions <custom-functions>`
|
2018-10-08 17:12:03 +03:00
|
|
|
- :doc:`Relationships <relationship>`
|
2019-10-18 11:29:47 +03:00
|
|
|
- :doc:`Computed Fields <computed-field>`
|
2018-10-08 17:12:03 +03:00
|
|
|
- :doc:`Permissions <permission>`
|
2018-10-25 10:22:51 +03:00
|
|
|
- :doc:`Event Triggers <event-triggers>`
|
2019-07-08 08:51:41 +03:00
|
|
|
- :doc:`Remote Schemas <remote-schemas>`
|
2019-05-16 09:13:25 +03:00
|
|
|
- :doc:`Query Collections <query-collections>`
|
2019-03-28 13:51:58 +03:00
|
|
|
- :doc:`Manage Metadata <manage-metadata>`
|
2018-10-08 17:12:03 +03:00
|
|
|
|
|
|
|
Response structure
|
|
|
|
------------------
|
|
|
|
|
|
|
|
.. list-table::
|
|
|
|
:widths: 10 10 30
|
|
|
|
:header-rows: 1
|
|
|
|
|
|
|
|
* - Status code
|
|
|
|
- Description
|
|
|
|
- Response structure
|
|
|
|
|
|
|
|
* - ``200``
|
|
|
|
- Success
|
|
|
|
- .. parsed-literal::
|
|
|
|
|
|
|
|
Request specific
|
|
|
|
|
|
|
|
* - ``400``
|
|
|
|
- Bad request
|
|
|
|
- .. code-block:: haskell
|
|
|
|
|
|
|
|
{
|
|
|
|
"path" : String,
|
|
|
|
"error" : String
|
|
|
|
}
|
|
|
|
|
|
|
|
* - ``401``
|
|
|
|
- Unauthorized
|
|
|
|
- .. code-block:: haskell
|
|
|
|
|
|
|
|
{
|
|
|
|
"error" : String
|
|
|
|
}
|
|
|
|
|
|
|
|
* - ``500``
|
|
|
|
- Internal server error
|
|
|
|
- .. code-block:: haskell
|
|
|
|
|
|
|
|
{
|
|
|
|
"error" : String
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Error codes
|
|
|
|
-----------
|
|
|
|
|
|
|
|
.. csv-table::
|
|
|
|
:file: dataerrors.csv
|
|
|
|
:widths: 10, 20, 70
|
|
|
|
:header-rows: 1
|
|
|
|
|
2019-09-11 10:17:14 +03:00
|
|
|
Disabling schema / metadata API
|
|
|
|
-------------------------------
|
2019-04-30 11:34:08 +03:00
|
|
|
|
|
|
|
Since this API can be used to make changes to the GraphQL schema, it can be
|
|
|
|
disabled, especially in production deployments.
|
|
|
|
|
|
|
|
The ``enabled-apis`` flag or the ``HASURA_GRAPHQL_ENABLED_APIS`` env var can be used to
|
2019-09-11 10:17:14 +03:00
|
|
|
enable/disable this API. By default, the schema/metadata API is enabled. To disable it, you need
|
|
|
|
to explicitly state that this API is not enabled i.e. remove it from the list of enabled APIs.
|
2019-04-30 11:34:08 +03:00
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
# enable only graphql api, disable metadata and pgdump
|
|
|
|
--enabled-apis="graphql"
|
|
|
|
HASURA_GRAPHQL_ENABLED_APIS="graphql"
|
|
|
|
|
2019-09-11 10:17:14 +03:00
|
|
|
See :doc:`../../deployment/graphql-engine-flags/reference` for info on setting the above flag/env var.
|
2019-04-30 11:34:08 +03:00
|
|
|
|
2018-10-08 17:12:03 +03:00
|
|
|
.. toctree::
|
|
|
|
:maxdepth: 1
|
|
|
|
:hidden:
|
|
|
|
|
|
|
|
Run SQL <run-sql>
|
2018-10-17 08:27:11 +03:00
|
|
|
Tables/Views <table-view>
|
2019-01-25 06:31:54 +03:00
|
|
|
Custom Functions <custom-functions>
|
2018-10-08 17:12:03 +03:00
|
|
|
Relationships <relationship>
|
|
|
|
Permissions <permission>
|
2019-10-18 11:29:47 +03:00
|
|
|
Computed Fields <computed-field>
|
2018-10-25 10:22:51 +03:00
|
|
|
Event Triggers <event-triggers>
|
2019-07-08 08:51:41 +03:00
|
|
|
Remote Schemas <remote-schemas>
|
2019-05-16 09:13:25 +03:00
|
|
|
Query Collections <query-collections>
|
2019-03-28 13:51:58 +03:00
|
|
|
Manage Metadata <manage-metadata>
|
2019-07-10 13:19:58 +03:00
|
|
|
Common syntax definitions <syntax-defs>
|