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.String',
  '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



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/generators/graphql_resource/graphql_resource_generator.rb', line 20

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?

  # Graphql Connection
  generate_graphql_connection(@resource) if options.connection?

  # 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