Skip to main content
Version: v3.x

Engine Plugins

Introduction

Engine plugins are a way to extend the functionality of the Hasura GraphQL Engine. Engine plugins are executed at various stages of the request lifecycle. Engine plugins can be used to modify the request, response, or to perform custom operations.

How LifeCyclePluginHooks work

Lifecycle plugin hooks are not generated by default when a Hasura project is created. They need to be manually added to the metadata. To see a guide, check out this page.

When you create a LifeCyclePluginHook, you define the configuration for the plugin in your metadata by passing information like the URL of the hosted plugin and its name. The plugin is then executed at the specified stage of the request lifecycle.

After creating a new LifeCyclePluginHook in your metadata, you'll need to create a new build using the CLI.

Examples

An example of a LifecyclePluginHook:
kind: LifecyclePluginHook
version: v1
definition:
name: cloudflare allowlist
url:
valueFromEnv: ALLOW_LIST_URL
pre: parse
config:
request:
headers:
additional:
hasura-m-auth:
valueFromEnv: M_AUTH_KEY
session: {}
rawRequest:
query: {}
variables: {}
FieldDescriptionReference
nameThe name of the lifecycle plugin hook.LifecyclePluginHookPreParse
urlThe URL to access the plugin.LifecyclePluginHookPreParse
preThe stage of the request lifecycle.LifecyclePluginHookPreParse
configConfiguration for the plugin.LifecyclePluginHookConfig
config.requestThe shape of the request object.LifecyclePluginHookConfigRequest
config.request.headersThe headers that should be included for each request.LifecyclePluginHookHeadersConfig
config.request.rawRequestThe configuration of the raw request, including any queries or variables.RawRequestConfig

Metadata structure

LifecyclePluginHook

Definition of a lifecycle plugin hook.

KeyValueRequiredDescription
kindLifecyclePluginHooktrue
versionv1true
definitionLifecyclePluginHookPreParsetrue

Example:

kind: LifecyclePluginHook
version: v1
definition:
pre: parse
name: test
url: http://localhost:8080
config:
request:
headers:
additional:
hasura-m-auth:
value: zZkhKqFjqXR4g5MZCsJUZCnhCcoPyZ
session: {}
rawRequest:
query: {}
variables: {}

LifecyclePluginHookPreParse

Definition of a lifecycle plugin hook for the pre-parse stage.

KeyValueRequiredDescription
preparsetrue
namestringtrueThe name of the lifecycle plugin hook.
urlstringtrueThe URL to access the lifecycle plugin hook.
configLifecyclePluginHookConfigtrueConfiguration for the lifecycle plugin hook.

LifecyclePluginHookConfig

Configuration for a lifecycle plugin hook.

KeyValueRequiredDescription
requestLifecyclePluginHookConfigRequesttrueConfiguration for the request to the lifecycle plugin hook.

LifecyclePluginHookConfigRequest

Configuration for a lifecycle plugin hook request.

KeyValueRequiredDescription
headersLifecyclePluginHookHeadersConfig / nullfalseConfiguration for the headers.
session{} / nullfalseConfiguration for the session (includes roles and session variables).
rawRequestRawRequestConfigtrueConfiguration for the raw request.

RawRequestConfig

Configuration for the raw request.

KeyValueRequiredDescription
query{} / nullfalseConfiguration for the query.
variables{} / nullfalseConfiguration for the variables.

LifecyclePluginHookHeadersConfig

Configuration for a lifecycle plugin hook headers.

KeyValueRequiredDescription
additionalHttpHeaders / nullfalseAdditional headers to be sent with the request.
forward[string]falseHeaders to be forwarded from the incoming request.

HttpHeaders

Key value map of HTTP headers to be sent with an HTTP request. The key is the header name and the value is a potential reference to an environment variable.

KeyValueRequiredDescription
<customKey>EnvironmentValuefalse

EnvironmentValue

Either a literal string or a reference to a Hasura secret

Must have exactly one of the following fields:

KeyValueRequiredDescription
valuestringfalse
valueFromEnvstringfalse
Loading...