GraphQL Ruby NameError uninitialized constant

542 Views Asked by At

I'm using graphql-ruby v.1.13.19 and I'm getting an error in my query file. Example of my query file:

class Types::Query < Types::BaseObject
  graphql_name 'Query'
  field :companyStats, Types::CompanyStats
  ...
  def companyStats
    Company.accessible_by(context[:current_ability])
  end
end

The error that I get when I query for organizations:

NameError (uninitialized constant Types::Query::Company
Did you mean?  Types::Company)

company_stats type

class Types::CompanyStats < Types::BaseObject
  graphql_name 'CompanyStats'

  field :count, Integer, null: false
end

graphql schema

class Schema < GraphQL::Schema
  mutation Types::Mutation
  query Types::Query

  use GraphQL::Batch
  def self.resolve_type(type, obj, ctx); end
end

The only solution that we found was to explicitly set the class as inheriting from Object class.

def companyStats
  Object::Company.accessible_by(context[:current_ability])
end
0

There are 0 best solutions below