class Graphql::Generators::MutationGenerator

TODO: What other options should be supported?

@example Generate a `GraphQL::Schema::RelayClassicMutation` by name

rails g graphql:mutation CreatePostMutation

Attributes

field_name[R]
file_name[R]
mutation_name[R]

Public Instance Methods

create_mutation_file() click to toggle source
# File lib/generators/graphql/mutation_generator.rb, line 29
def create_mutation_file
  unless @behavior == :revoke
    create_mutation_root_type
  else
    log :gsub, "#{options[:directory]}/types/mutation_type.rb"
  end

  template "mutation.erb", "#{options[:directory]}/mutations/#{file_name}.rb"

  sentinel = /class .*MutationType\s*<\s*[^\s]+?\n/m
  in_root do
    gsub_file "#{options[:directory]}/types/mutation_type.rb", /  \# TODO\: Add Mutations as fields\s*\n/m, ""
    inject_into_file "#{options[:directory]}/types/mutation_type.rb", "    field :#{field_name}, mutation: Mutations::#{mutation_name}\n", after: sentinel, verbose: false, force: false
  end
end

Private Instance Methods

assign_names!(name) click to toggle source
# File lib/generators/graphql/mutation_generator.rb, line 47
def assign_names!(name)
  @field_name = name.camelize(:lower)
  @mutation_name = name.camelize(:upper)
  @file_name = name.camelize.underscore
end