Sha256: f79c35eb54249a8bc3be6d7d98920e6a61a1772333c5d15b894c28c6aa3ac633

Contents?: true

Size: 1.09 KB

Versions: 108

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true
require 'rails/generators'
require 'rails/generators/named_base'
require_relative 'core'

module Graphql
  module Generators
    # TODO: What other options should be supported?
    #
    # @example Generate a `GraphQL::Schema::RelayClassicMutation` by name
    #     rails g graphql:mutation CreatePostMutation
    class MutationGenerator < Rails::Generators::NamedBase
      include Core

      desc "Create a Relay Classic mutation by name"
      source_root File.expand_path('../templates', __FILE__)

      def create_mutation_file
        template "mutation.erb", File.join(options[:directory], "/mutations/", class_path, "#{file_name}.rb")

        sentinel = /class .*MutationType\s*<\s*[^\s]+?\n/m
        in_root do
          path = "#{options[:directory]}/types/mutation_type.rb"
          invoke "graphql:install:mutation_root" unless File.exist?(path)
          inject_into_file "#{options[:directory]}/types/mutation_type.rb", "    field :#{file_name}, mutation: Mutations::#{class_name}\n", after: sentinel, verbose: false, force: false
        end
      end
    end
  end
end

Version data entries

108 entries across 108 versions & 1 rubygems

Version Path
graphql-2.4.9 lib/generators/graphql/mutation_generator.rb
graphql-2.4.8 lib/generators/graphql/mutation_generator.rb
graphql-2.4.7 lib/generators/graphql/mutation_generator.rb
graphql-2.4.6 lib/generators/graphql/mutation_generator.rb
graphql-2.4.5 lib/generators/graphql/mutation_generator.rb
graphql-2.4.4 lib/generators/graphql/mutation_generator.rb
graphql-2.4.3 lib/generators/graphql/mutation_generator.rb
graphql-2.4.2 lib/generators/graphql/mutation_generator.rb
graphql-2.4.1 lib/generators/graphql/mutation_generator.rb
graphql-2.4.0 lib/generators/graphql/mutation_generator.rb
graphql-2.3.20 lib/generators/graphql/mutation_generator.rb
graphql-2.3.19 lib/generators/graphql/mutation_generator.rb
graphql-2.3.18 lib/generators/graphql/mutation_generator.rb
graphql-2.3.17 lib/generators/graphql/mutation_generator.rb
graphql-2.3.16 lib/generators/graphql/mutation_generator.rb
graphql-2.3.15 lib/generators/graphql/mutation_generator.rb
graphql-2.3.14 lib/generators/graphql/mutation_generator.rb
graphql-2.3.13 lib/generators/graphql/mutation_generator.rb
graphql-2.3.12 lib/generators/graphql/mutation_generator.rb
graphql-2.3.11 lib/generators/graphql/mutation_generator.rb