Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Working with mixins #64

Open
mmahalwy opened this issue Oct 3, 2018 · 0 comments
Open

Working with mixins #64

mmahalwy opened this issue Oct 3, 2018 · 0 comments

Comments

@mmahalwy
Copy link

mmahalwy commented Oct 3, 2018

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? 
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant