Skip to content

Zeitwerk Rails 6 - autoloading warnings #2456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
srgoldman opened this issue Aug 29, 2019 · 6 comments
Closed

Zeitwerk Rails 6 - autoloading warnings #2456

srgoldman opened this issue Aug 29, 2019 · 6 comments

Comments

@srgoldman
Copy link

Adding the graphql-errors gem and this initializer:

GraphQL::Errors.configure(BlogSchema) do
  rescue_from GraphQL::UnauthorizedError do |e|
    GraphQL::ExecutionError.new e.message
  end
end

to the sample blog app (fresh Rails 6 app) results in the following error when running specs:

$ rails spec
/Users/sethgoldman/.rbenv/versions/2.6.3/bin/ruby -I/Users/sethgoldman/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rspec-core-3.8.2/lib:/Users/sethgoldman/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rspec-support-3.8.2/lib /Users/sethgoldman/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rspec-core-3.8.2/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb
DEPRECATION WARNING: Initialization autoloaded the constants Types, Types::BaseObject, Types::MutationType, Types::User, Types::QueryType, and BlogSchema.

Being able to do this is deprecated. Autoloading during initialization is going
to be an error condition in future versions of Rails.

Reloading does not reboot the application, and therefore code executed during
initialization does not run again. So, if you reload Types, for example,
the expected changes won't be reflected in that stale Module object.

These autoloaded constants have been unloaded.

Please, check the "Autoloading and Reloading Constants" guide for solutions.
 (called from <top (required)> at /Users/sethgoldman/Code/blog/config/environment.rb:5)
..*

Pending: (Failures listed here are expected and do not affect your suite's status)

  1) User add some examples to (or delete) /Users/sethgoldman/Code/blog/spec/models/user_spec.rb
     # Not yet implemented
     # ./spec/models/user_spec.rb:4


Finished in 0.017 seconds (files took 1.12 seconds to load)
3 examples, 0 failures, 1 pending

I've uploaded the code here: https://github.com/srgoldman/rails6_blog_issue

@rmosolgo
Copy link
Owner

rmosolgo commented Sep 3, 2019

Thanks for reporting this issue and sharing a reproduction of it.

Autoloading during initialization

It looks like we can get rid of this by moving the GraphQL::Errors setup into the schema file, for example:

rmosolgo/rails6_blog_issue@bc9d4b8

Then, when I ran the tests, I didn't get that warning:

~/code/rails6_blog_issue $ rails db:migrate && rails spec
== 20190829211314 CreateUsers: migrating ======================================
-- create_table(:users)
   -> 0.0060s
== 20190829211314 CreateUsers: migrated (0.0065s) =============================

/Users/rmosolgo/.rbenv/versions/2.6.3/bin/ruby -I/Users/rmosolgo/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rspec-core-3.8.2/lib:/Users/rmosolgo/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rspec-support-3.8.2/lib /Users/rmosolgo/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rspec-core-3.8.2/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb
..*

Pending: (Failures listed here are expected and do not affect your suite's status)

  1) User add some examples to (or delete) /Users/rmosolgo/code/rails6_blog_issue/spec/models/user_spec.rb
     # Not yet implemented
     # ./spec/models/user_spec.rb:4


Finished in 0.03172 seconds (files took 1.7 seconds to load)
3 examples, 0 failures, 1 pending

Also, I've just added some error handling to the gem which is inspired heavily by exaspark's work on graphql-errors, so that might help: #2458

Please let me know if that doesn't work for you!

@rmosolgo rmosolgo closed this as completed Sep 3, 2019
@srgoldman
Copy link
Author

Thanks @rmosolgo. It worked for the blog example but didn't do the trick in my real application so I suspect that some other initializer must be loading the schema. I'll poke around and see if I can track it down and I'll take a look at the new error handling as well.

@srgoldman
Copy link
Author

Found it. The schema was being referenced in our datadog initialization. I'll have to figure out a way around that.

@macdonaldr93
Copy link

I have this exactly same problem. What was your solution?

@srgoldman
Copy link
Author

I was referencing the schema in an initializer which apparently was running before other things were set up properly. I just removed the reference from the initializer so it would get loaded normally and that fixed it for me.

@macdonaldr93
Copy link

I switched to using use GraphQL::Tracing::DataDogTracing directly in the schema instead of the initializer. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants