Class: Hai::Install::GraphqlGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_mutationsObject



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_queriesObject



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_typesObject



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_rubyObject



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_preloadObject



7
8
9
# File 'lib/generators/install/graphql_generator.rb', line 7

def rails_preload
  Rails.application.eager_load!
end