Class: Hai::Install::GraphqlGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Hai::Install::GraphqlGenerator
- Defined in:
- lib/generators/install/graphql_generator.rb
Instance Method Summary collapse
- #add_mutations ⇒ Object
- #add_queries ⇒ Object
- #add_types ⇒ Object
- #install_graphql_ruby ⇒ Object
- #rails_preload ⇒ Object
Instance Method Details
#add_mutations ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/generators/install/graphql_generator.rb', line 36 def add_mutations inject_into_file "app/graphql/types/mutation_type.rb", after: "class MutationType < Types::BaseObject" do <<~RUBY.indent(4) include Hai::GraphQL hai_mutation(#{model_names.join(', ')}) RUBY end end |
#add_queries ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/generators/install/graphql_generator.rb', line 27 def add_queries inject_into_file "app/graphql/types/query_type.rb", after: "include GraphQL::Types::Relay::HasNodesField" do <<~RUBY.indent(4) include Hai::GraphQL hai_query(#{model_names.join(', ')}) RUBY end end |
#add_types ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/generators/install/graphql_generator.rb', line 17 def add_types hai_types = "hay_types(#{model_names.join(', ')})" inject_into_file "app/graphql/#{app_name.underscore}_schema.rb", after: "class #{app_name}Schema < GraphQL::Schema" do <<~RUBY.indent(4) include Hai::GraphQL::Types hai_types(#{model_names.join(', ')}) RUBY end end |
#install_graphql_ruby ⇒ Object
11 12 13 14 15 |
# File 'lib/generators/install/graphql_generator.rb', line 11 def install_graphql_ruby gem 'graphql' run "bundle install" run "rails generate graphql:install" end |
#rails_preload ⇒ Object
7 8 9 |
# File 'lib/generators/install/graphql_generator.rb', line 7 def rails_preload Rails.application.eager_load! end |