Describe the bug
We are a pure-ruby app. Rails is defined as a module because we use the rails-html-sanitizer gem but Rails.env is not present. All of a sudden, a change in 2.5.3 (still broken in 2.5.4) caused the app to fail to boot. Presumable #5326.
Specifically this line is not protected adequately: https://github.com/rmosolgo/graphql-ruby/blob/master/lib/graphql/schema/visibility.rb#L15
Check this out:
irb(main):006> defined?(Rails)
=> "constant"
irb(main):007> Rails.env
(irb):7:in '<main>': undefined method 'env' for module Rails (NoMethodError)
from <internal:kernel>:168:in 'Kernel#loop'
from bin/console:23:in '<main>'
irb(main):008> defined?(Rails.env)
=> nil
Versions
graphql version: 2.5.3 and 2.5.4
rails (or other framework): none
GraphQL schema
Include relevant types and fields (in Ruby is best, in GraphQL IDL is ok). Any custom extensions, etc?
class Schema < GraphQL::Schema
mutation(RootMutation)
query(RootQuery)
use GraphQL::Schema::AlwaysVisible
...
end
GraphQL query
Example GraphQL query and response (if query execution is involved)
N/A - app won't even boot
Steps to reproduce
Include use GraphQL::Schema::AlwaysVisible in a non-Rails app that has a Rails module defined
Expected behavior
No error
Actual behavior
Error
Click to view exception backtrace
/home/ben/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/graphql-2.5.4/lib/graphql/schema/visibility.rb:15:in 'GraphQL::Schema::Visibility.use': undefined method 'env' for module Rails (NoMethodError)
def self.use(schema, dynamic: false, profiles: EmptyObjects::EMPTY_HASH, preload: (defined?(Rails) ? Rails.env.production? : nil), migration_errors: false)
^^^^
from /home/ben/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/graphql-2.5.4/lib/graphql/schema.rb:319:in 'GraphQL::Schema.use'
from /home/ben/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/graphql-2.5.4/lib/graphql/schema/always_visible.rb:6:in 'GraphQL::Schema::AlwaysVisible.use'
from /home/ben/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/graphql-2.5.4/lib/graphql/schema.rb:321:in 'GraphQL::Schema.use'
from /home/ben/projects/api/app/graphql/schema.rb:23:in '<class:Schema>'
from /home/ben/projects/api/app/graphql/schema.rb:18:in '<top (required)>'
from /home/ben/.rbenv/versions/3.4.1/lib/ruby/3.4.0/bundled_gems.rb:82:in 'Kernel.require'
from /home/ben/.rbenv/versions/3.4.1/lib/ruby/3.4.0/bundled_gems.rb:82:in 'block (2 levels) in Kernel#replace_require'
from /home/ben/projects/api/app/graphql.rb:13:in '<top (required)>'
from /home/ben/.rbenv/versions/3.4.1/lib/ruby/3.4.0/bundled_gems.rb:82:in 'Kernel.require'
from /home/ben/.rbenv/versions/3.4.1/lib/ruby/3.4.0/bundled_gems.rb:82:in 'block (2 levels) in Kernel#replace_require'
from /home/ben/projects/api/app.rb:22:in 'block in <top (required)>'
from /home/ben/projects/api/config/api.rb:82:in 'Api.silence_db_logs'
from /home/ben/projects/api/app.rb:15:in '<top (required)>'
from config.ru:5:in 'Kernel#require_relative'
from config.ru:5:in 'block in <main>'
from /home/ben/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/rack-2.2.13/lib/rack/builder.rb:116:in 'Kernel#eval'
from /home/ben/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/rack-2.2.13/lib/rack/builder.rb:116:in 'Rack::Builder.new_from_string'
from /home/ben/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/rack-2.2.13/lib/rack/builder.rb:105:in 'Rack::Builder.load_file'
from /home/ben/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/rack-2.2.13/lib/rack/builder.rb:66:in 'Rack::Builder.parse_file'
from /home/ben/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/iodine-0.7.58/exe/iodine:219:in 'Iodine::Base::CLI.try_file'
from /home/ben/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/iodine-0.7.58/exe/iodine:235:in 'Iodine::Base::CLI.get_app_opts'
from /home/ben/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/iodine-0.7.58/exe/iodine:272:in 'Iodine::Base::CLI.call'
from /home/ben/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/iodine-0.7.58/exe/iodine:280:in '<top (required)>'
from /home/ben/.rbenv/versions/3.4.1/bin/iodine:25:in 'Kernel#load'
from /home/ben/.rbenv/versions/3.4.1/bin/iodine:25:in '<top (required)>'
from /home/ben/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/bundler-2.6.3/lib/bundler/cli/exec.rb:59:in 'Kernel.load'
from /home/ben/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/bundler-2.6.3/lib/bundler/cli/exec.rb:59:in 'Bundler::CLI::Exec#kernel_load'
from /home/ben/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/bundler-2.6.3/lib/bundler/cli/exec.rb:23:in 'Bundler::CLI::Exec#run'
from /home/ben/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/bundler-2.6.3/lib/bundler/cli.rb:452:in 'Bundler::CLI#exec'
from /home/ben/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/bundler-2.6.3/lib/bundler/vendor/thor/lib/thor/command.rb:28:in 'Bundler::Thor::Command#run'
from /home/ben/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/bundler-2.6.3/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in 'Bundler::Thor::Invocation#invoke_command'
from /home/ben/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/bundler-2.6.3/lib/bundler/vendor/thor/lib/thor.rb:538:in 'Bundler::Thor.dispatch'
from /home/ben/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/bundler-2.6.3/lib/bundler/cli.rb:35:in 'Bundler::CLI.dispatch'
from /home/ben/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/bundler-2.6.3/lib/bundler/vendor/thor/lib/thor/base.rb:584:in 'Bundler::Thor::Base::ClassMethods#start'
from /home/ben/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/bundler-2.6.3/lib/bundler/cli.rb:29:in 'Bundler::CLI.start'
from /home/ben/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/bundler-2.6.3/exe/bundle:28:in 'block in <top (required)>'
from /home/ben/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/bundler-2.6.3/lib/bundler/friendly_errors.rb:117:in 'Bundler.with_friendly_errors'
from /home/ben/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/bundler-2.6.3/exe/bundle:20:in '<top (required)>'
from /home/ben/.rbenv/versions/3.4.1/bin/bundle:25:in 'Kernel#load'
from /home/ben/.rbenv/versions/3.4.1/bin/bundle:25:in '<main>'
</details>
**Additional context**
Add any other context about the problem here.
With these details, we can efficiently hunt down the bug!
Describe the bug
We are a pure-ruby app.
Railsis defined as a module because we use the rails-html-sanitizer gem butRails.envis not present. All of a sudden, a change in 2.5.3 (still broken in 2.5.4) caused the app to fail to boot. Presumable #5326.Specifically this line is not protected adequately: https://github.com/rmosolgo/graphql-ruby/blob/master/lib/graphql/schema/visibility.rb#L15
Check this out:
Versions
graphqlversion: 2.5.3 and 2.5.4rails(or other framework): noneGraphQL schema
Include relevant types and fields (in Ruby is best, in GraphQL IDL is ok). Any custom extensions, etc?
GraphQL query
Example GraphQL query and response (if query execution is involved)
N/A - app won't even boot
Steps to reproduce
Include
use GraphQL::Schema::AlwaysVisiblein a non-Rails app that has aRailsmodule definedExpected behavior
No error
Actual behavior
Error
Click to view exception backtrace