【发布时间】:2019-06-28 17:49:22
【问题描述】:
我正在尝试使用 RoR 在 Graphql 中编写我的第一个突变。好像是这样的:
app/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
但每次我使用 Graphiql 提出请求时(像这样:)
mutation createPost {
createPost(input:{
title:"dupa",
body:"dupa"
}) {
id
}
}
帖子已保存在数据库中,但我收到错误消息
"error": {
"message": "can't write unknown attribute `client_mutation_id`" [...]
而不是请求的 id 我怎么解决这个问题? 这是我的
app/graphql/mutations/base_mutation.rb
module Mutations
class BaseMutation < GraphQL::Schema::RelayClassicMutation
end
end
app/graphql/types/mutation_type.rb
module Types
class MutationType < Types::BaseObject
field :create_post, mutation: Mutations::CreatePost
end
end
github 链接如果有帮助的话:https://github.com/giraffecms/GiraffeCMS-backend-rails/tree/blog/app/graphql
【问题讨论】:
标签: ruby-on-rails ruby graphql