Schema/Metadata API Reference: Custom Types

Table of contents

Introduction

Custom Types are user-defined GraphQL types which help to define Actions.

Deprecation

In versions v2.0.0 and above, the schema/metadata API is deprecated in favour of the schema API and the metadata API.

Though for backwards compatibility, the schema/metadata APIs will continue to function.

set_custom_types

set_custom_types is used to set user-defined GraphQL types. This API will replace the given types with existing ones.

POST /v1/query HTTP/1.1
Content-Type: application/json
X-Hasura-Role: admin

{
  "type": "set_custom_types",
  "args": {
    "scalars": [],
    "enums": [],
    "input_objects": [
      {
        "name": "User",
        "fields": [
          {
            "name": "username",
            "type": "String!"
          },
          {
            "name": "password",
            "type": "String!"
          }
        ]
      }
    ],
    "objects": [
      {
        "name": "UserId",
        "fields": [
          {
            "name": "id",
            "type": "Int!"
          }
        ],
        "relationships": [
          {
            "name": "posts",
            "type": "array",
            "remote_table": "post",
            "field_mapping": {
              "id": "user_id"
            }
          }
        ]
      }
    ]
  }
}

Args syntax

Key Required Schema Description
input_objects false Array of InputObjectType Set of GraphQL Input Object
objects false Array of ObjectType Set of GraphQL Object
scalars false Array of ScalarType Set of GraphQL Scalar
enums false Array of EnumType Set of GraphQL Enum