File: mutation_root_generator.rb

package info (click to toggle)
ruby-graphql 2.2.17-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,584 kB
  • sloc: ruby: 67,505; ansic: 1,753; yacc: 831; javascript: 331; makefile: 6
file content (34 lines) | stat: -rw-r--r-- 1,071 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# frozen_string_literal: true

require "rails/generators/base"
require_relative "../core"

module Graphql
  module Generators
    module Install
      class MutationRootGenerator < Rails::Generators::Base
        include Core

        desc "Create mutation base type, mutation root tipe, and adds the latter to the schema"
        source_root File.expand_path('../templates', __FILE__)

        class_option :schema,
          type: :string,
          default: nil,
          desc: "Name for the schema constant (default: {app_name}Schema)"

        class_option :skip_keeps,
          type: :boolean,
          default: false,
          desc: "Skip .keep files for source control"

        def generate
          create_dir("#{options[:directory]}/mutations")
          template("base_mutation.erb", "#{options[:directory]}/mutations/base_mutation.rb", { skip: true })
          template("mutation_type.erb", "#{options[:directory]}/types/mutation_type.rb", { skip: true })
          insert_root_type('mutation', 'MutationType') 
        end
      end
    end
  end
end