Class: GraphqlRails::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/graphql_rails/install_generator.rb

Overview

Add GraphQL to a Rails app with ‘rails g graphql_rails:install`.

Setup a folder structure for GraphQL:

“‘

  • app/

    • controllers

      • graphql_controller.rb

      • graphql

        • graphql_application_controller.rb

    • graphql

      • graphql_router.rb

“‘

Instance Method Summary collapse

Instance Method Details

#create_folder_structureObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/generators/graphql_rails/install_generator.rb', line 26

def create_folder_structure
  empty_directory('app/controllers')
  template('graphql_controller.erb', 'app/controllers/graphql_controller.rb')

  empty_directory('app/controllers/graphql')
  template('graphql_application_controller.erb', 'app/controllers/graphql/graphql_application_controller.rb')
  template('example_users_controller.erb', 'app/controllers/graphql/example_users_controller.rb')

  application do
    "config.autoload_paths << 'app/graphql'"
  end

  empty_directory('app/graphql')
  template('graphql_router.erb', 'app/graphql/graphql_router.rb')

  route('post "/graphql", to: "graphql#execute"')

  if File.directory?('spec') # rubocop:disable Style/GuardClause
    empty_directory('spec/graphql')
    template('graphql_router_spec.erb', 'spec/app/graphql/graphql_router_spec.rb')
  end
end