【发布时间】:2017-05-04 00:24:30
【问题描述】:
我已经为此苦苦挣扎了一个多小时,但似乎无法让它发挥作用。
我将 GraphQL 的 ruby 实现与 Rails 一起使用,并且我正在尝试使用 GraphQL 执行 User.all。我有以下定义字段用户的 QueryType。
QueryType = GraphQL::ObjectType.define do
name "Query"
description "The query root for this schema"
field :users do
types[IndexUserType]
resolve -> () {
User.all
}
end
end
以及IndexUserType定义如下:
IndexUserType = GraphQL::ObjectType.define do
name "IndexUserType"
description "An Index User"
field :firstname, types.String
end
我正在尝试使用以下查询获取所有用户的名字:
query={ users { firstname } }
通常我可以对 Has-Many 关系进行以下操作,但这不起作用,我认为这是因为没有父级就无法设置“obj”。
resolve -> (obj, args, ctx) {
obj.cousins
}
【问题讨论】:
标签: ruby-on-rails ruby rubygems graphql