Class: GraphqlResourceGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/graphql_resource/graphql_resource_generator.rb

Constant Summary collapse

TYPES_MAPPING =
{
  'id' => '!types.ID',
  'uuid' => '!types.String',
  'boolean' => 'types.Boolean',
  'float' => 'types.Float',
  'decimal' => 'types.Float',
  'integer' => 'types.Int',
  'bigint' => 'types.Int'
}.freeze

Instance Method Summary collapse

Instance Method Details

#create_graphql_filesObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/generators/graphql_resource/graphql_resource_generator.rb', line 17

def create_graphql_files
  return if args.blank?
  parse_args

  # Generate migration
  generate_create_migration(@resource, @fields_to_migration) if options.migration?

  # Graphql Basic mutations
  generate_basic_mutations(@resource) if options.mutations?

  # Graphql Type
  generate_graphql_type(@resource) if options.graphql_type?

  # Model
  generate_model(@resource) if options.model?

  # Service
  generate_service(@resource) if options.service?
  handle_many_to_many_fields(@resource) if options.propagation?

  # Propagation
  add_has_many_to_models(@resource) if options.propagation?
  add_has_many_fields_to_types(@resource) if options.propagation?

  system('bundle exec rails db:migrate') if options.migrate?
end