2020-01-14 15:57:45 +03:00
|
|
|
.. meta::
|
|
|
|
:description: Manage metadata with the Hasura schema/metadata API
|
|
|
|
:keywords: hasura, docs, schema/metadata API, API reference, metadata
|
|
|
|
|
2020-03-11 22:42:36 +03:00
|
|
|
.. _api_manage_metadata:
|
|
|
|
|
2019-03-28 13:51:58 +03:00
|
|
|
Schema/Metadata API Reference: Manage metadata
|
|
|
|
==============================================
|
|
|
|
|
|
|
|
.. contents:: Table of contents
|
|
|
|
:backlinks: none
|
|
|
|
:depth: 1
|
|
|
|
:local:
|
|
|
|
|
2020-08-25 14:53:25 +03:00
|
|
|
Introduction
|
|
|
|
------------
|
|
|
|
|
2019-03-28 13:51:58 +03:00
|
|
|
APIs to manage Hasura metadata which is stored in ``hdb_catalog`` schema.
|
|
|
|
|
|
|
|
.. _export_metadata:
|
|
|
|
|
|
|
|
export_metadata
|
|
|
|
---------------
|
|
|
|
|
2021-02-19 05:39:30 +03:00
|
|
|
``export_metadata`` is used to export the current metadata from the server as a JSON file.
|
2019-03-28 13:51:58 +03:00
|
|
|
|
|
|
|
.. code-block:: http
|
|
|
|
|
|
|
|
POST /v1/query HTTP/1.1
|
|
|
|
Content-Type: application/json
|
|
|
|
X-Hasura-Role: admin
|
|
|
|
|
|
|
|
{
|
|
|
|
"type" : "export_metadata",
|
|
|
|
"args": {}
|
|
|
|
}
|
|
|
|
|
2021-02-08 12:11:40 +03:00
|
|
|
Response:
|
|
|
|
|
|
|
|
The response JSON will be the metadata object. The structure of the metadata object
|
|
|
|
is just a JSON version of the :ref:`metadata files <metadata_format_v2>` generated by
|
|
|
|
the CLI.
|
|
|
|
|
2021-02-19 05:39:30 +03:00
|
|
|
|
|
|
|
.. _replace_metadata:
|
2019-03-28 13:51:58 +03:00
|
|
|
|
|
|
|
replace_metadata
|
|
|
|
----------------
|
|
|
|
|
|
|
|
``replace_metadata`` is used to replace/import metadata into Hasura. Existing
|
|
|
|
metadata will be replaced with the new one.
|
|
|
|
|
2021-02-16 12:38:25 +03:00
|
|
|
.. code-block:: none
|
2019-03-28 13:51:58 +03:00
|
|
|
|
2020-06-19 16:20:56 +03:00
|
|
|
POST /v1/query HTTP/1.1
|
|
|
|
Content-Type: application/json
|
|
|
|
X-Hasura-Role: admin
|
2019-03-28 13:51:58 +03:00
|
|
|
|
2020-06-19 16:20:56 +03:00
|
|
|
{
|
|
|
|
"type" : "replace_metadata",
|
2021-02-19 05:39:30 +03:00
|
|
|
"version": 1 | 2 (optional),
|
2021-02-16 11:08:19 +03:00
|
|
|
"args": <replace-metadata-args>
|
2020-06-19 16:20:56 +03:00
|
|
|
}
|
2019-03-28 13:51:58 +03:00
|
|
|
|
2021-02-16 12:38:25 +03:00
|
|
|
.. _replace_metadata_syntax_v1:
|
2019-03-28 13:51:58 +03:00
|
|
|
|
|
|
|
Args syntax
|
|
|
|
^^^^^^^^^^^
|
|
|
|
|
2021-02-16 11:08:19 +03:00
|
|
|
If version is set to 1, then args should be the JSON object which is same as
|
|
|
|
the output of :ref:`export_metadata`.
|
|
|
|
|
|
|
|
For version 2, the following structure is used:
|
|
|
|
|
2021-02-16 12:38:25 +03:00
|
|
|
.. code-block:: none
|
2021-02-16 11:08:19 +03:00
|
|
|
|
|
|
|
{
|
2021-02-19 05:39:30 +03:00
|
|
|
allow_inconsistent_metadata: Boolean,
|
2021-02-16 11:08:19 +03:00
|
|
|
metadata: metadata-object
|
|
|
|
}
|
|
|
|
|
|
|
|
.. list-table::
|
|
|
|
:header-rows: 1
|
|
|
|
|
|
|
|
* - Key
|
|
|
|
- Required
|
|
|
|
- Schema
|
|
|
|
- Description
|
|
|
|
* - allow_inconsistent_metadata
|
|
|
|
- false
|
|
|
|
- Boolean
|
|
|
|
- If set to ``true``, metadata will be replaced with a warning in the response indicating which items are inconsistent (default: ``false``)
|
|
|
|
* - metadata
|
|
|
|
- true
|
|
|
|
- :ref:`export_metadata`
|
|
|
|
- The metadata that will replace the current metadata.
|
|
|
|
|
|
|
|
If the version is not specified, then it is inferred from the format of ``args``.
|
|
|
|
|
|
|
|
Responses
|
|
|
|
^^^^^^^^^
|
|
|
|
|
2021-02-16 12:38:25 +03:00
|
|
|
Example with inconsistencies:
|
2021-02-16 11:08:19 +03:00
|
|
|
|
2021-02-16 12:38:25 +03:00
|
|
|
.. code-block:: none
|
2021-02-16 11:08:19 +03:00
|
|
|
|
2021-02-16 12:38:25 +03:00
|
|
|
HTTP/1.1 400 Bad Request
|
2021-02-16 11:08:19 +03:00
|
|
|
|
2021-02-16 12:38:25 +03:00
|
|
|
{
|
2021-02-16 11:08:19 +03:00
|
|
|
"internal": [
|
2021-02-16 12:38:25 +03:00
|
|
|
{
|
|
|
|
"type": "remote_schema",
|
|
|
|
"reason": "HTTP exception occurred while sending the request to http://localhost:5000/hello-graphql",
|
2021-02-16 11:08:19 +03:00
|
|
|
"definition": {
|
2021-02-16 12:38:25 +03:00
|
|
|
"definition": {
|
2021-02-16 11:08:19 +03:00
|
|
|
"url": "http://localhost:5000/hello-graphql",
|
|
|
|
"forward_client_headers": false
|
2021-02-16 12:38:25 +03:00
|
|
|
},
|
|
|
|
"name": "test",
|
|
|
|
"permissions": [],
|
|
|
|
"comment": "testing replace metadata with remote schemas"
|
|
|
|
}
|
|
|
|
}, ...
|
|
|
|
]
|
|
|
|
}
|
2019-03-28 13:51:58 +03:00
|
|
|
|
|
|
|
.. _reload_metadata:
|
|
|
|
|
|
|
|
reload_metadata
|
|
|
|
---------------
|
|
|
|
|
2019-09-11 10:17:14 +03:00
|
|
|
``reload_metadata`` should be used when there is a change in underlying Postgres
|
2019-03-28 13:51:58 +03:00
|
|
|
database that Hasura should be aware of. Example: a new column is added to a
|
|
|
|
table using ``psql`` and this column should now be added to the GraphQL schema.
|
|
|
|
|
|
|
|
.. code-block:: http
|
|
|
|
|
|
|
|
POST /v1/query HTTP/1.1
|
|
|
|
Content-Type: application/json
|
|
|
|
X-Hasura-Role: admin
|
|
|
|
|
|
|
|
{
|
|
|
|
"type" : "reload_metadata",
|
2020-03-26 14:52:20 +03:00
|
|
|
"args": {
|
|
|
|
"reload_remote_schemas": true
|
|
|
|
}
|
2019-03-28 13:51:58 +03:00
|
|
|
}
|
|
|
|
|
2020-03-26 14:52:20 +03:00
|
|
|
.. _reload_metadata_args_syntax:
|
|
|
|
|
|
|
|
Args syntax
|
|
|
|
^^^^^^^^^^^
|
|
|
|
|
|
|
|
.. list-table::
|
|
|
|
:header-rows: 1
|
|
|
|
|
|
|
|
* - Key
|
|
|
|
- Required
|
|
|
|
- Schema
|
|
|
|
- Description
|
|
|
|
* - reload_remote_schemas
|
|
|
|
- false
|
|
|
|
- Boolean
|
|
|
|
- If set to ``true``, all remote schemas' (including inconsistent ones) cached GraphQL schemas are refreshed (default: ``false``)
|
|
|
|
|
2019-03-28 13:51:58 +03:00
|
|
|
.. _clear_metadata:
|
|
|
|
|
|
|
|
clear_metadata
|
|
|
|
--------------
|
|
|
|
|
|
|
|
``clear_metadata`` can be used to reset the state of Hasura -- clean the current
|
|
|
|
state by forgetting the tables tracked, relationships, permissions, event
|
|
|
|
triggers etc.
|
|
|
|
|
|
|
|
.. code-block:: http
|
|
|
|
|
|
|
|
POST /v1/query HTTP/1.1
|
|
|
|
Content-Type: application/json
|
|
|
|
X-Hasura-Role: admin
|
|
|
|
|
|
|
|
{
|
|
|
|
"type" : "clear_metadata",
|
|
|
|
"args": {}
|
|
|
|
}
|
2019-04-17 19:29:39 +03:00
|
|
|
|
|
|
|
.. _get_inconsistent_metadata:
|
|
|
|
|
|
|
|
get_inconsistent_metadata
|
|
|
|
-------------------------
|
|
|
|
|
|
|
|
``get_inconsistent_metadata`` can be used to fetch all inconsistent metadata objects.
|
|
|
|
|
|
|
|
.. code-block:: http
|
|
|
|
|
|
|
|
POST /v1/query HTTP/1.1
|
|
|
|
Content-Type: application/json
|
|
|
|
X-Hasura-Role: admin
|
|
|
|
|
|
|
|
{
|
|
|
|
"type": "get_inconsistent_metadata",
|
|
|
|
"args": {}
|
|
|
|
}
|
|
|
|
|
2020-06-19 16:20:56 +03:00
|
|
|
Response:
|
2019-04-17 19:29:39 +03:00
|
|
|
|
|
|
|
.. code-block:: json
|
|
|
|
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"definition": {
|
|
|
|
"using": {
|
|
|
|
"foreign_key_constraint_on": {
|
|
|
|
"column": "author_id",
|
|
|
|
"table": "article"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"name": "articles",
|
|
|
|
"comment": null,
|
|
|
|
"table": "author"
|
|
|
|
},
|
|
|
|
"reason": "table \"article\" does not exist",
|
|
|
|
"type": "array_relation"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"definition": {
|
|
|
|
"using": {
|
|
|
|
"foreign_key_constraint_on": "author_id"
|
|
|
|
},
|
|
|
|
"name": "author",
|
|
|
|
"comment": null,
|
|
|
|
"table": "article"
|
|
|
|
},
|
|
|
|
"reason": "table \"article\" does not exist",
|
|
|
|
"type": "object_relation"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"definition": "article",
|
|
|
|
"reason": "no such table/view exists in postgres : \"article\"",
|
|
|
|
"type": "table"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
.. _drop_inconsistent_metadata:
|
|
|
|
|
|
|
|
drop_inconsistent_metadata
|
|
|
|
--------------------------
|
|
|
|
|
2019-09-11 10:17:14 +03:00
|
|
|
``drop_inconsistent_metadata`` can be used to purge all inconsistent objects from the metadata.
|
2019-04-17 19:29:39 +03:00
|
|
|
|
|
|
|
.. code-block:: http
|
|
|
|
|
|
|
|
POST /v1/query HTTP/1.1
|
|
|
|
Content-Type: application/json
|
|
|
|
X-Hasura-Role: admin
|
|
|
|
|
|
|
|
{
|
|
|
|
"type": "drop_inconsistent_metadata",
|
|
|
|
"args": {}
|
|
|
|
}
|