微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Elixir Absinthe GraphQL,Union resolve_type list_of/1

如何解决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 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?