Setting up GraphQL on Rails @ rails graphql:install -> ERROR: method_missing': undefined method `parent_name' for RailsGraphql::Application:Class

Setting up GraphQL on Rails @ rails graphql:install -> ERROR: method_missing': undefined method `parent_name' for RailsGraphql::Application:Class

我是 Rails 和 GraphQL 的新手。在尝试 create/set-up 一个新的 Rails+GraphQL 网络应用程序时,我尝试使用 2 个不同的教程

Howtographql.com && DigitalOcean

在这两种情况下(不同的目录)我在安装 rails graphql:install 时遇到同样的错误(我在全球和本地都试过)。尚未编写自定义代码,仅处于设置阶段。错误似乎来自我本地驱动器上的 Rails 文件夹,所以这可能是我在计算机上安装 rails 的方式?以下是完整的错误信息和 Gemfile:


Gemfile

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.6.3'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.1.0'
# Use postgresql as the database for Active Record
gem 'pg', '~> 1.1'
# Use Puma as the app server
gem 'puma', '~> 5.0'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
# gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Active Storage variant
# gem 'image_processing', '~> 1.2'

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.4', require: false

# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
# gem 'rack-cors'

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
  gem 'listen', '~> 3.3'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'graphiql-rails'
end

gem 'graphql', '1.9.18'

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]


控制台 - 错误消息

rails_graphql % rails g graphql:install
Running via Spring preloader in process 41567
       exist  app/graphql/types
   identical  app/graphql/types/.keep
Traceback (most recent call last):
        35: from -e:1:in `<main>'
        34: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        33: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        32: from /Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.0/lib/active_support/fork_tracker.rb:26:in `fork'
        31: from /Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.0/lib/active_support/fork_tracker.rb:8:in `fork'
        30: from /Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.0/lib/active_support/fork_tracker.rb:8:in `fork'
        29: from /Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.0/lib/active_support/fork_tracker.rb:10:in `block in fork'
        28: from /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:59:in `load'
        27: from /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:59:in `load'
        26: from /Users/renatabubic/projects/ruby-projects/rails_graphql/bin/rails:5:in `<main>'
        25: from /Library/Ruby/Gems/2.6.0/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in `require'
        24: from /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
        23: from /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
        22: from /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        21: from /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
        20: from /Library/Ruby/Gems/2.6.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
        19: from /Library/Ruby/Gems/2.6.0/gems/railties-6.1.0/lib/rails/commands.rb:18:in `<main>'
        18: from /Library/Ruby/Gems/2.6.0/gems/railties-6.1.0/lib/rails/command.rb:50:in `invoke'
        17: from /Library/Ruby/Gems/2.6.0/gems/railties-6.1.0/lib/rails/command/base.rb:69:in `perform'
        16: from /Library/Ruby/Gems/2.6.0/gems/thor-1.0.1/lib/thor.rb:392:in `dispatch'
        15: from /Library/Ruby/Gems/2.6.0/gems/thor-1.0.1/lib/thor/invocation.rb:127:in `invoke_command'
        14: from /Library/Ruby/Gems/2.6.0/gems/thor-1.0.1/lib/thor/command.rb:27:in `run'
        13: from /Library/Ruby/Gems/2.6.0/gems/railties-6.1.0/lib/rails/commands/generate/generate_command.rb:26:in `perform'
        12: from /Library/Ruby/Gems/2.6.0/gems/railties-6.1.0/lib/rails/generators.rb:275:in `invoke'
        11: from /Library/Ruby/Gems/2.6.0/gems/thor-1.0.1/lib/thor/base.rb:485:in `start'
        10: from /Library/Ruby/Gems/2.6.0/gems/thor-1.0.1/lib/thor/group.rb:232:in `dispatch'
         9: from /Library/Ruby/Gems/2.6.0/gems/thor-1.0.1/lib/thor/invocation.rb:134:in `invoke_all'
         8: from /Library/Ruby/Gems/2.6.0/gems/thor-1.0.1/lib/thor/invocation.rb:134:in `map'
         7: from /Library/Ruby/Gems/2.6.0/gems/thor-1.0.1/lib/thor/invocation.rb:134:in `each'
         6: from /Library/Ruby/Gems/2.6.0/gems/thor-1.0.1/lib/thor/invocation.rb:134:in `block in invoke_all'
         5: from /Library/Ruby/Gems/2.6.0/gems/thor-1.0.1/lib/thor/invocation.rb:127:in `invoke_command'
         4: from /Library/Ruby/Gems/2.6.0/gems/thor-1.0.1/lib/thor/command.rb:27:in `run'
         3: from /Library/Ruby/Gems/2.6.0/gems/graphql-1.9.18/lib/generators/graphql/install_generator.rb:97:in `create_folder_structure'
         2: from /Library/Ruby/Gems/2.6.0/gems/graphql-1.9.18/lib/generators/graphql/core.rb:34:in `schema_file_path'
         1: from /Library/Ruby/Gems/2.6.0/gems/graphql-1.9.18/lib/generators/graphql/core.rb:52:in `schema_name'
/Library/Ruby/Gems/2.6.0/gems/railties-6.1.0/lib/rails/railtie.rb:209:in `method_missing': undefined method `parent_name' for RailsGraphql::Application:Class (NoMethodError) 

我刚刚 运行 遇到了同样的问题。 通过更新我的 gem 版本解决了这个问题:

gem 'graphql', '1.11.6'