Current section

Files

Jump to
ash_json_api lib ash_json_api.ex
Raw

lib/ash_json_api.ex

defmodule AshJsonApi do
@moduledoc """
Introspection functions for `AshJsonApi` apis.
"""
alias Ash.Dsl.Extension
def prefix(api) do
Extension.get_opt(api, [:json_api], :prefix, nil, true)
end
def serve_schema?(api) do
Extension.get_opt(api, [:json_api], :serve_schema?, false, true)
end
def authorize?(api) do
Extension.get_opt(api, [:json_api], :authorize?, true, true)
end
def log_errors?(api) do
Extension.get_opt(api, [:json_api], :log_errors?, true, true)
end
defmacro forward(path, api, opts \\ []) do
quote bind_quoted: [path: path, api: api, opts: opts] do
case Code.ensure_compiled(api) do
{:module, module} ->
forward(path, :persistent_term.get({api, :ash_json_api, :router}, nil), opts)
_error ->
# We used to raise here, but this failing almost always implies
# a compilation error in the api, which will be more informative
# if we just let that be raised
:ok
end
end
end
def router(api) do
:persistent_term.get({api, :ash_json_api, :router}, nil)
end
end