我想要做这样的事情:是否有可能使用权威人士授权与graphql
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及其方法?