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 towindow.locationin 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- Thealtair-staticnpm package version to load from CDN. Defaults to"8.5.2".:schema- An Absinthe schema module. When set andabsinthe_plugis available, non-HTML requests are delegated toAbsinthe.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.