【发布时间】:2021-04-07 02:30:13
【问题描述】:
我正在尝试在 Absinthe 中实现 GraphQL 联合类型。
我们有两个对象,:foo 和 :bar 和一个联合类型 :info,它解析为其中一种类型。
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
由于某种原因,每个自定义解析器都接收一个空映射 %{} 作为其第一个参数。
在解析类型时,我们确实有一个带有 "info" 字段(以及更多字段)的映射。
为什么自定义解析器没有收到与联合类型解析器相同的映射?
【问题讨论】: