Class: GraphqlBulkCreateMutationsGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- GraphqlBulkCreateMutationsGenerator
- Defined in:
- lib/generators/graphql_mutations/graphql_bulk_create_mutations_generator.rb
Instance Method Summary collapse
- #generate ⇒ Object
- #generate_bulk_create_mutation(dir, resource) ⇒ Object
- #resource_class(resource) ⇒ Object
Instance Method Details
#generate ⇒ Object
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", <<~STRING #{resource_class(resource)}::Mutations::BulkCreate = GraphQL::Field.define do description 'creates some #{resource_class(resource).pluralize}' type types[#{resource_class(resource)}::Type] argument :#{resource}, types[#{resource_class(resource)}::Mutations::InputType] resolve ApplicationService.call(:#{resource}, :bulk_create) end STRING ) end |
#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 |