Schema/Metadata API Reference: Custom Functions

Introduction

Track/untrack a custom SQL function in the Hasura GraphQL engine.

Only tracked custom functions are available for querying/mutating/subscribing data over the GraphQL API.

track_function

track_function is used to add a custom SQL function to the GraphQL schema. Also refer a note here.

Add an SQL function search_articles:

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

{
    "type": "track_function",
    "args": {
        "schema": "public",
        "name": "search_articles"
    }
}

track_function v2

Version 2 of track_function is used to add a custom SQL function to the GraphQL schema with configuration. Also refer a note here.

Add an SQL function called search_articles with a Hasura session argument.

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

{
    "type": "track_function",
    "version": 2,
    "args": {
        "function": {
            "schema": "public",
            "name": "search_articles"
        },
        "configuration": {
            "session_argument": "hasura_session"
        }
    }
}

Args syntax

Key Required Schema Description
function true FunctionName Name of the SQL function
configuration false Function Configuration Configuration for the SQL function

Function Configuration

Key Required Schema Description
session_argument false String Function argument which accepts session info JSON

Note

Currently, only functions which satisfy the following constraints can be exposed over the GraphQL API (terminology from Postgres docs):

  • Function behaviour: ONLY STABLE or IMMUTABLE
  • Return type: MUST be SETOF <table-name>
  • Argument modes: ONLY IN

untrack_function

untrack_function is used to remove a SQL function from the GraphQL schema.

Remove an SQL function search_articles:

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

{
    "type": "untrack_function",
    "args": {
        "schema": "public",
        "name": "search_articles"
    }
}

Args syntax

Key Required Schema Description
table true FunctionName Name of the SQL function