我想要做這樣的事情:是否有可能使用權威人士授權與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及其方法?