【发布时间】:2017-09-15 12:47:10
【问题描述】:
我想做这样的事情:
authorize record, :some_action
在解析graphql字段或突变(例如突变)
module Mutations::CreateLink
CreateLink = GraphQL::Relay::Mutation.define do
name "CreateLink"
input_field :name, types.String
input_field :url, types.String
input_field :description, types.String
return_field :link, Types::LinkType
resolve -> (object, inputs, ctx) {
Rails::logger.ap ctx[:current_user]
Rails::logger.ap inputs[:name]
ctx[:current_user]
@link = Link.new(name: inputs[:name], url: inputs[:url], description: inputs[:description])
authorize @link, :create?
response = {
link: @link
}
}
end
end
运行上述程序时会显示此错误: NoMethodError - GraphQL::Relay::Mutation 无法定义“授权”
通常你会写
include Pundit
在您的控制器中,但将其添加到 GraphqlController 没有任何区别。
如何让 graphql 了解 pundit 及其方法?
【问题讨论】:
标签: ruby-on-rails graphql pundit