我正在尝试使用 RoR 在 Graphql 中编写我的第一个突变。看起来像这样:
应用程序/graphql/mutations/create_post.rb
module Mutations
class CreatePost < Mutations::BaseMutation
argument :title, String, required: true
argument :body, String, required: true
type Types::PostType
def resolve(title: nil, body: nil)
Post.create!(title: title, body: body)
end
end
end
Run Code Online (Sandbox Code Playgroud)
但是每次我使用Graphiql提出请求时(像这样:)
mutation createPost {
createPost(input:{
title:"dupa",
body:"dupa"
}) {
id
}
}
Run Code Online (Sandbox Code Playgroud)
帖子被保存在数据库中,但我收到一个错误
"error": {
"message": "can't write unknown attribute `client_mutation_id`" [...]
Run Code Online (Sandbox Code Playgroud)
而不是请求的 id 我该如何解决这个问题?这是我的
应用程序/graphql/mutations/base_mutation.rb
module Mutations
class BaseMutation < GraphQL::Schema::RelayClassicMutation
end
end
Run Code Online (Sandbox Code Playgroud)
应用程序/graphql/types/mutation_type.rb
module Types
class MutationType < Types::BaseObject
field :create_post, mutation: …Run Code Online (Sandbox Code Playgroud) 我正在学习红宝石,我正在写一个简单的文字游戏,我们正在与对手作战.我有一个班级"英雄",我有这样的代码
def attack(enemy)
enemy.hp -= attack_damage
puts enemy.name + " HP:" + enemy.hp.to_s
enemy.attack(# This is the place where I need to refer to object from what I'm calling this method #)
end
Run Code Online (Sandbox Code Playgroud)
当我想要打架我只是创造新的英雄和敌人,但我不能使用递归,因为我不知道如何引用对象,正如我所说,所以战斗持续只有1击
abundzu = Hero.new("abundzu", 100, 25, 5)
herr = Hero.new("herr", 50, 25, 5)
abundzu.attack(herr)
Run Code Online (Sandbox Code Playgroud)