palkan/action_policy-graphql

Howto setup for graphql ruby 1.9.14

lifeiscontent opened this issue · 3 comments

a few questions I have is one,

in the case that my current_user is called viewer in context, what does the modification of that look like to setup ActionPolicy GraphQL?

also, I initially tried this:

# frozen_string_literal: true

class Types::Base < GraphQL::Schema::Object
  include ActionPolicy::GraphQL::Behaviour
  field_class Fields::Base

  def current_user
    context[:viewer]
  end
end

but I am having issues it seems.

when I followed the way to authorize objects at a type level .e.g:

class Types::Post < Types::Base
  #... 

  def self.authorized?(object, context)
    super &&
      object.allowed_to?(
        :show?,
        object,
        context: {user: context[:viewer]}
      )
  end
end

I get an undefined method allowed_to?

The example from the doc wasn't valid. Sorry for confusion.

The following snippet should work in the just released version (0.3.1):

def self.authorized?(object, context)
  super &&
    allowed_to?(
      :show?,
      object,
      context: {user: context[:viewer]}
    )
end

@palkan I still get undefined method `allowed_to?' for Types::Post:Class

@palkan nevermind, needed to restart, thank you!