我需要帮助。我正在寻找一种方法来解决联合中的 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
在上面的代码中。我试图将 list_of(:person) 放入 resolve_type 并返回这样的错误
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, non_null(:string))
resolve(&CommunityResolver.search/3)
end
end
...
union :search_result do
description "A search result"
types [:person, :business]
resolve_type fn
%Person{}, _ -> :person
%Business{}, _ -> :business
end
end
它返回
(BadMapError) expected a map, got: [%{name: "John"}, ...
我也试过把它放在这样的类型中,但也有错误。
...
types [list_of(:person), list_of(:business)]
resolve_type fn
...
有没有可能的解决方法?