AbsintheAltair (absinthe_altair v2026.5.1)

Copy Markdown View Source

A Plug for embedding the Altair GraphQL Client into Phoenix and Absinthe applications.

When a request arrives with Accept: text/html, the plug serves the Altair single-page application loaded from CDN. Otherwise, it optionally delegates to Absinthe.Plug for standard GraphQL API processing.

Usage

# In your Phoenix router
forward "/altair", AbsintheAltair, endpoint_url: "/api/graphql"

Options

Any Altair configuration property can be passed as a snake_case atom option. Keys are automatically converted to camelCase for JavaScript (e.g. :initial_query becomes initialQuery).

Common options:

  • :endpoint_url - The GraphQL endpoint URL. Accepts a string or {module, function} tuple. Defaults to window.location in the browser.

  • :subscriptions_endpoint - WebSocket URL for subscriptions. Accepts a string or {module, function} tuple.

  • :subscriptions_protocol - Subscription protocol. One of "ws", "graphql-ws", "graphql-sse", "app-sync", or "action-cable".

  • :initial_query - Pre-populated GraphQL query string.

  • :initial_variables - Pre-populated variables string.

  • :initial_headers - Map of default headers, or {module, function} tuple.

  • :initial_settings - Map of Altair application settings.

Plug-specific options:

  • :altair_version - The altair-static npm package version to load from CDN. Defaults to "8.5.2".

  • :schema - An Absinthe schema module. When set and absinthe_plug is available, non-HTML requests are delegated to Absinthe.Plug.

Any Absinthe.Plug options (e.g. :context, :pipeline) are passed through to Absinthe.Plug.init/1 when :schema is present and absinthe_plug is available.