palkan/action_policy-graphql

authorize! method doesn't work inside mutation

psemehen opened this issue · 1 comments

Get error while authorizing inside mutation(think the same will be with resolver).

These steps are done:

class Types::BaseObject < GraphQL::Schema::Object
include ActionPolicy::GraphQL::Behaviour
end

For using authorization helpers in mutations

class Types::BaseMutation < GraphQL::Schema::Mutation
include ActionPolicy::GraphQL::Behaviour
end

For using authorization helpers in resolvers

class Types::BaseResolver < GraphQL::Schema::Resolver
include ActionPolicy::GraphQL::Behaviour
end

Error message:

*** NoMethodError Exception: undefined method `authorize!' for #Mutations::Companies::CreateCompanyMutation:0x00007fb12c8fcd40
Did you mean? authorized?

But when authorize inside mutation_type.rb then it works:
field :create_company, mutation: Mutations::Companies::CreateCompanyMutation, authorize: {to: :create?, with: CompanyPolicy}

Have a look please :)

Closed. My fault.
Included ActionPolicy::GraphQL::Behaviour into base_mutation.rb inside mutations folder and it works as expected.