Class: GraphqlBulkCreateMutationsGenerator

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

Instance Method Summary collapse

Instance Method Details

#generateObject



3
4
5
6
7
8
# File 'lib/generators/graphql_mutations/graphql_bulk_create_mutations_generator.rb', line 3

def generate
  Graphql::Rails::Api::Config.query_resources.each do |resource|
    dir = "#{Rails.root}/app/graphql/#{resource.pluralize}/mutations"
    generate_bulk_create_mutation(dir, resource) if Dir.exist?(dir)
  end
end

#generate_bulk_create_mutation(dir, resource) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/generators/graphql_mutations/graphql_bulk_create_mutations_generator.rb', line 10

def generate_bulk_create_mutation(dir, resource)
  File.write(
    "#{dir}/bulk_create.rb",
    "      \#{resource_class(resource)}::Mutations::BulkCreate = GraphQL::Field.define do\n        description 'creates some \#{resource_class(resource).pluralize}'\n        type types[\#{resource_class(resource)}::Type]\n\n        argument :\#{resource}, types[\#{resource_class(resource)}::Mutations::InputType]\n\n        resolve ApplicationService.call(:\#{resource}, :bulk_create)\n      end\n    STRING\n  )\nend\n"

#resource_class(resource) ⇒ Object



26
27
28
# File 'lib/generators/graphql_mutations/graphql_bulk_create_mutations_generator.rb', line 26

def resource_class(resource)
  resource.pluralize.camelize
end