Packages
absinthe_relay
1.5.0-beta.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/schema/phase.ex
defmodule Absinthe.Relay.Schema.Phase do
use Absinthe.Phase
alias Absinthe.Blueprint
alias Absinthe.Blueprint.Schema
def run(blueprint, _) do
{blueprint, _acc} = Blueprint.postwalk(blueprint, [], &collect_types/2)
{:ok, blueprint}
end
defp collect_types(%Schema.SchemaDefinition{} = schema, new_types) do
new_types =
Enum.reject(new_types, fn new_type ->
Enum.any?(schema.type_definitions, fn t -> t.identifier == new_type.identifier end)
end)
schema =
schema
|> Map.update!(:type_definitions, &(new_types ++ &1))
|> Blueprint.prewalk(&fill_nodes/1)
{schema, []}
end
defp collect_types(%{__private__: private} = node, types) do
attrs = private[:absinthe_relay] || []
types =
Enum.reduce(attrs, types, fn
{kind, {:fill, style}}, types ->
List.wrap(style.additional_types(kind, node)) ++ types
_, types ->
types
end)
{node, types}
end
defp collect_types(node, acc) do
{node, acc}
end
defp fill_nodes(%{__private__: private} = node) do
Enum.reduce(private[:absinthe_relay] || [], node, fn
{type, {:fill, style}}, node -> style.fillout(type, node)
_, node -> node
end)
end
defp fill_nodes(node) do
node
end
end