I'm trying to implement a GraphQL union type in Absinthe.
We have two objects, :foo
and :bar
and a union type :info
that resolves to one of those types.
object :contact do
field :info, list_of(:info)
end
object :foo do
field :phone, non_null(:string),
resolve: fn foo, _ ->
IO.inspect(foo) # <-- is %{}
{:ok, "hardcodedfornow"}
end
end
object :bar do
field :id, non_null(:string),
resolve: fn id, _b ->
IO.inspect(id) # <-- is %{}
{:ok, "hardcodedfornow"}
end
end
union :info do
description("")
types([:foo, :bar])
resolve_type(fn
%{"info" => "foo"}, _ ->
:foo
%{"info" => "bar"}, _ ->
:bar
end)
end
For some reason, each custom resolver is receiving an empty map %{}
as its first argument.
When resolving the type, we do have a map with an "info"
field (as well as more fields).
Why are the custom resolvers not receiving the same map that the union type resolver receives?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…