Packages
absinthe_relay
1.6.0
1.6.0
1.5.2
1.5.1
1.5.0
1.5.0-rc.0
1.5.0-beta.0
1.5.0-alpha.0
1.4.6
1.4.5
1.4.4
1.4.3
1.4.2
1.4.1
1.4.0
1.4.0-rc.1
1.4.0-rc.0
1.3.6
1.3.5
1.3.4
1.3.3
1.3.2
1.3.1
1.3.0
1.3.0-rc.0
1.3.0-beta.1
1.3.0-beta.0
1.2.0
1.2.0-alpha0
1.2.0-alpha.3
1.2.0-alpha.2
1.2.0-alpha.1
0.9.4
0.9.3
0.9.2
0.9.1
0.9.0
0.8.1
0.8.0
Relay framework support for Absinthe
Current section
Files
Jump to
Current section
Files
lib/absinthe/relay/node/parse_ids/config.ex
defmodule Absinthe.Relay.Node.ParseIDs.Config do
alias Absinthe.Relay.Node.ParseIDs.{Namespace, Rule}
defstruct children: []
@type node_t :: Namespace.t() | Rule.t()
@type t :: %__MODULE__{
children: [node_t]
}
def parse!(config) when is_map(config) do
parse!(Keyword.new(config))
end
def parse!(config) when is_list(config) do
parse!(config, %__MODULE__{})
end
defp parse!(config, %{children: _} = node) when is_list(config) do
children =
Enum.map(config, fn
{key, [{_, _} | _] = value} ->
parse!(value, %Namespace{key: key})
{key, value} ->
parse!(value, %Rule{key: key})
other ->
raise "Could not parse #{__MODULE__} namespace element: #{inspect(other)}"
end)
%{node | children: children}
end
defp parse!(value, %Rule{} = node) when is_atom(value) do
%{node | expected_types: [value], output_mode: :simple}
end
defp parse!(value, %Rule{} = node) when is_list(value) do
%{node | expected_types: value, output_mode: :full}
end
defp parse!(value, %Rule{}) do
raise "Could not parse #{__MODULE__} rule: #{inspect(value)}"
end
end