AbsintheAltair.Config (absinthe_altair v2026.5.1)

Copy Markdown View Source

Handles configuration resolution and JavaScript initialization for the Altair GraphQL Client plug.

Any snake_case Elixir option key is automatically converted to its camelCase JavaScript equivalent (e.g. :initial_query becomes initialQuery). This means all Altair configuration properties are supported — not just a hardcoded subset.

Configuration values can be static strings/maps or {module, function} tuples that are resolved at request time. Functions may accept zero arguments or one argument (the Plug.Conn).

Summary

Functions

Builds a JavaScript object literal string for AltairGraphQL.init().

Escapes a string for safe interpolation inside a JavaScript single-quoted string.

Resolves all dynamic configuration values and builds the template config map.

Resolves a configuration value. Static values pass through unchanged. {module, function} tuples are called with the conn (arity 1) or without arguments (arity 0).

Converts a snake_case atom to a camelCase string.

Functions

build_init_options(config)

@spec build_init_options(map()) :: String.t()

Builds a JavaScript object literal string for AltairGraphQL.init().

String values are escaped and quoted. Map values are JSON-encoded. A nil endpoint_url produces an unquoted JS expression using window.location. Nil/absent options are omitted.

js_escape(string)

@spec js_escape(String.t()) :: String.t()

Escapes a string for safe interpolation inside a JavaScript single-quoted string.

resolve_options(opts, conn)

@spec resolve_options(map(), Plug.Conn.t()) :: map()

Resolves all dynamic configuration values and builds the template config map.

Returns a map with :base_url and :init_options_js keys ready for the EEx template.

resolve_value(value, conn)

@spec resolve_value(term(), Plug.Conn.t()) :: term()

Resolves a configuration value. Static values pass through unchanged. {module, function} tuples are called with the conn (arity 1) or without arguments (arity 0).

to_js_key(key)

@spec to_js_key(atom()) :: String.t()

Converts a snake_case atom to a camelCase string.

The special key :endpoint_url is converted to "endpointURL" to match Altair's expected casing.

Examples

iex> AbsintheAltair.Config.to_js_key(:initial_query)
"initialQuery"

iex> AbsintheAltair.Config.to_js_key(:endpoint_url)
"endpointURL"