ontohub / graphql-pundit

Pundit authorization helpers for the GraphQL Ruby gem
MIT License
111 stars 31 forks source link

Working with mixins #64

Open mmahalwy opened 6 years ago

mmahalwy commented 6 years ago

I am trying to abstract the different queries made (and welcoming suggestions!).

I have file:


  def self.included(child_class)
    child_class.field(:companies, [Types::CompanyType], null: false)
    child_class.field(:company, Types::CompanyType, null: false) do
      argument :id, Integer, required: true
    end
  end

  # then implement the field
  def companies
    CompanyPolicy::Scope.new(context[:current_user], ::Company).resolve
  end

  def company(id:)
    ::Company.find(id)
  end
end``` 

That is then included in my query type:
```class Types::QueryType < GraphQL::Schema::Object
  graphql_name "Query"

  include Queries::Models::Company
end
```.

My challenge is that `CompanyPolicy::Scope.new(context[:current_user], ::Company).resolve` works for the time being but not great for the long run. How can I change this up to work with this? 

Also, in the docs there is reference to `GraphQL::Schema::FieldType` then there is no more mention of it in the README, how is it being used?