如何解决Elixir Absinthe GraphQL,Union resolve_type list_of/1
我需要帮助。我正在寻找一种解决联合中的 list_of(:object) 的方法。 这就是我所做的。
object :community_queries do
field :search,type: :search_result do
arg(:keyword,non_null(:string))
resolve(&CommunityResolver.search/3)
end
end
...
union :search_result do
description "A search result"
types [:person,:business]
resolve_type fn
%Person{},_ -> list_of(:person)
%Business{},_ -> list_of(:business)
end
end
在上面的代码中。我试图在 resolve_type 中放入一个 list_of(:person) 并且它返回这样的错误
invalid quoted expression: %Absinthe.Blueprint.TypeReference.List{errors: [],of_type: :person}
然后我尝试了这个
object :community_queries do
field :search,type: list_of(:search_result) do
arg(:keyword,_ -> :person
%Business{},_ -> :business
end
end
它回来了
(BadMapError) expected a map,got: [%{name: "John"},...
...
types [list_of(:person),list_of(:business)]
resolve_type fn
...
是否有可能的解决方法?
解决方法
object :community_queries,do
field :search,type: list_of(:search_result) do
arg(:keyword,non_null(:string))
resolve(&CommunityResolver.search/3)
end
end
:community_queries
是一个查询参数,应该定义为一个字段而不是一个查找个人或企业的对象,我们称它们为 users
。这个定义的字段看起来像是返回 :search_result
。
field :community_queries,:search_result do
arg(:keyword,non_null(:string))
resolve(&CommunityResolver.search/3)
end
您需要定义 search_result
对象的外观,听起来像是 users
的列表。
更多关于查询参数 here
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。