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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...