Git Product home page Git Product logo

Comments (4)

rmosolgo avatar rmosolgo commented on June 27, 2024

Hmmm, tricky! Some suggestions:

  • Was there a preceeding error in your development server output? Sometimes one error can happen, then trigger a later error because the file couldn't be loaded properly.
  • You can try adding a prefix :: to clarify that you want a top-level constant. That might help rails load it properly (although it seems like it should work as written!), eg ::Question.where(...).
  • What's the full path of the file where class Question is defined? (Is it app/models/question.rb?)

from graphiql-rails.

shaneardell avatar shaneardell commented on June 27, 2024

The full server output:

Started POST "/graphql" for 127.0.0.1 at 2019-02-27 13:48:01 -0700
Processing by GraphqlsController#create as */*
  Parameters: {"query"=>"query {\n  questions {\n    uuid\n  }\n}\n", "variables"=>nil, "graphql"=>{"query"=>"query {\n  questions {\n    uuid\n  }\n}\n", "variables"=>nil}}
  AuthToken Load (1.4ms)  SELECT  "auth_tokens".* FROM "auth_tokens" WHERE "auth_tokens"."expired_at" IS NULL AND "auth_tokens"."token" = $1 LIMIT $2  [["token", "**********"], ["LIMIT", 1]]
  ↳ app/controllers/application_controller.rb:35
  User Load (0.5ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["id", 4], ["LIMIT", 1]]
  ↳ app/controllers/application_controller.rb:42
   (0.1ms)  BEGIN
  ↳ app/controllers/application_controller.rb:42
  AuthToken Update (0.3ms)  UPDATE "auth_tokens" SET "last_used_at" = $1, "updated_at" = $2 WHERE "auth_tokens"."id" = $3  [["last_used_at", "2019-02-27 20:48:01.568622"], ["updated_at", "2019-02-27 20:48:01.571236"], ["id", 1]]
  ↳ app/controllers/application_controller.rb:42
   (0.3ms)  COMMIT
  ↳ app/controllers/application_controller.rb:42
Completed 500 Internal Server Error in 24ms (ActiveRecord: 6.2ms)



NameError (uninitialized constant Resolvers::Questions::Question):

app/graphql/resolvers/questions.rb:16:in `resolve'
app/controllers/graphqls_controller.rb:31:in `create'

I'm not seeing anything that points to a preceding error.

Adding the :: prefix does work, but feels weird.

The Question class is defined as a Rails model (app/models/question.rb). The core of the app can be thought of like a versioned question bank.

class Question < ApplicationRecord
  include Trackable
  include Identifiable

  belongs_to :organization
  has_many   :question_versions

  accepts_nested_attributes_for :question_versions

  validates :name, presence: true

  enum field_type: [
    :short_text,
    :paragraph_text,
    :number,
    :date,
    :time,
    :single_select,
    :multi_select,
    :likert,
    :photo,
    :audio,
    :video,
  ]

  def latest_version
    question_versions.order(:version_number).last
  end
end

from graphiql-rails.

rmosolgo avatar rmosolgo commented on June 27, 2024

Thanks for sharing! I was hoping to see a smoking gun, but nothin' 😖

I guess since the adding :: works, we can be sure that the file does load correctly.

Sorry, I don't really have any other suggestion :(

If you don't like adding the explicit ::, the other option is to manually load the file using require_dependency at the top of the file, eg

require_dependency "question"

That will make sure Rails loads the file and can reload it as needed.

Sorry, I don't have any other ideas how graphiql-rails could be involved here!

from graphiql-rails.

shaneardell avatar shaneardell commented on June 27, 2024

Yeah, it occurs to me I probably should have opened the issue under the graphql-ruby project instead.

My gut says it has everything to do with Rails' autoloading, especially since it's behaving differently in both prod and test environments vs local.

require_dependency 'question' works and feels a little better than the :: prefix.

I'll go with that for now. Thanks so much @rmosolgo for looking into it.

from graphiql-rails.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.