Class: Graphql::Generators::InitGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_gemsObject



6
7
8
9
10
11
# File 'lib/generators/graphql/init_generator.rb', line 6

def add_gems
  gem 'graphql'
  gem 'graphql-relay'
  gem 'graphiql-rails'
  gem 'graphql-formatter'
end

#autoload_pathsObject



18
19
20
21
22
23
# File 'lib/generators/graphql/init_generator.rb', line 18

def autoload_paths
  application do "  config.autoload_paths += Dir[\"\#{config.root}/app/graphql/**/\"]\n  RUBY\n  end\nend\n"

#copy_templatesObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/generators/graphql/init_generator.rb', line 25

def copy_templates
  copy_file 'controllers/graph_ql_controller.rb', 'app/controllers/graph_ql_controller.rb'
  copy_file 'models/root_level.rb', 'app/models/root_level.rb'
  copy_file 'graph/relay_schema.rb', 'app/graphql/relay_schema.rb'
  copy_file 'graph/node_identification.rb', 'app/graphql/node_identification.rb'
  copy_file 'graph/types/root_level_type.rb', 'app/graphql/types/root_level_type.rb'
  copy_file 'graph/types/query_type.rb', 'app/graphql/types/query_type.rb'
  copy_file 'graph/types/mutation_type.rb', 'app/graphql/types/mutation_type.rb'

  copy_file 'config/graphiql.rb', 'config/initializers/graphiql.rb'
end

#routesObject



13
14
15
16
# File 'lib/generators/graphql/init_generator.rb', line 13

def routes
  route "post 'graphql' => 'graph_ql#execute'"
  route "mount GraphiQL::Rails::Engine, at: '/graphiql', graphql_path: '/graphql'"
end