我对使用 Rails 完全陌生,我正在尝试使用 ruby-graphql 创建一个基本的 crud 应用程序,以对 sqlite3 数据库进行带有活动记录的简单查找查询。我设置了一个用户类型
class UserType < Types::BaseObject
description "A user type "
field :id, ID, null: false
field :username, String, null: false
field :email, String, null: false
field :email_confirmed, Boolean, null:false
field :first_name, String , null:false
field :last_name, String, null:false
field :biography, String, null:true
field :avatar, String, null:true
field :created_at, GraphQL::Types::ISO8601DateTime, null:false
field :updated_at, GraphQL::Types::ISO8601DateTime, null:false
end
然后我设置查询:
field :user, UserType, null:false,
description: "Get a single user" do
argument :username, String, required: true
end
def user(username:)
User.find(username)
end
我的查询是:
{
user(username:"test"){
username
}
}
我收到以下错误:
{
"error": {
"message": "no implicit conversion of #<Class:0x000000000b975440> into Hash",
"backtrace": [
"C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/graphql-1.9.13/lib/graphql/schema/field.rb:519:in `block in resolve'",
如果有人可以帮助我,我将不胜感激。如何在 Ruby/Rails 中进行这种转换?