当我尝试在graphql中更新对象时,我遇到了此图像的错误。
遇到此错误
我写的代码。
module Mutations
class UpdateLink < BaseMutation
argument :link_id, ID, required: true
argument :description, String, required: false
argument :url, String, required: false
type Types::LinkType
def resolve(**args)
link = Link.find(args[:link_id])
link.update!(
url: args[:url],
description: args[:description],
user: context[:current_user]
)
end
end
end
这里的错误信息
Link.description, trying:
- `Types::LinkType#description`, which did not exist - `TrueClass#description`, which did not exist - Looking up hash key `:description` or `"description"` on `true`, but it wasn't a Hash To implement this field, define one of the methods above (and check for typos)
我不知道如何解决这个错误。
请教我如何解决这个问题。
link.update!
返回一个布尔值true(因为它是方法的最后一行),而resolve
方法期望Types::LinkType
。试着在resolve方法的末尾返回链接。