souls 0.51.2 → 0.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/README.md +4 -1
 - data/exe/souls +4 -202
 - data/lib/souls/api/generate/application.rb +97 -94
 - data/lib/souls/api/generate/connection.rb +5 -4
 - data/lib/souls/api/generate/edge.rb +5 -4
 - data/lib/souls/api/generate/index.rb +0 -1
 - data/lib/souls/api/generate/manager.rb +9 -7
 - data/lib/souls/api/generate/model.rb +16 -18
 - data/lib/souls/api/generate/mutation.rb +217 -218
 - data/lib/souls/api/generate/policy.rb +5 -5
 - data/lib/souls/api/generate/query.rb +51 -51
 - data/lib/souls/api/generate/resolver.rb +115 -115
 - data/lib/souls/api/generate/rspec_factory.rb +53 -53
 - data/lib/souls/api/generate/rspec_model.rb +5 -5
 - data/lib/souls/api/generate/rspec_mutation.rb +178 -178
 - data/lib/souls/api/generate/rspec_policy.rb +5 -5
 - data/lib/souls/api/generate/rspec_query.rb +111 -111
 - data/lib/souls/api/generate/rspec_resolver.rb +163 -163
 - data/lib/souls/api/generate/type.rb +66 -66
 - data/lib/souls/api/index.rb +7 -4
 - data/lib/souls/api/update/index.rb +15 -0
 - data/lib/souls/api/update/mutation.rb +68 -64
 - data/lib/souls/api/update/resolver.rb +59 -60
 - data/lib/souls/api/update/rspec_factory.rb +40 -39
 - data/lib/souls/api/update/rspec_mutation.rb +84 -83
 - data/lib/souls/api/update/rspec_resolver.rb +70 -69
 - data/lib/souls/api/update/type.rb +39 -38
 - data/lib/souls/cli/console/index.rb +13 -1
 - data/lib/souls/cli/create/index.rb +97 -93
 - data/lib/souls/cli/db/index.rb +122 -1
 - data/lib/souls/cli/docker/index.rb +30 -38
 - data/lib/souls/cli/gcloud/compute/index.rb +100 -98
 - data/lib/souls/cli/gcloud/iam/index.rb +84 -69
 - data/lib/souls/cli/gcloud/index.rb +36 -35
 - data/lib/souls/cli/gcloud/pubsub/subscriptions.rb +40 -27
 - data/lib/souls/cli/gcloud/pubsub/topics.rb +16 -10
 - data/lib/souls/cli/gcloud/run/index.rb +23 -17
 - data/lib/souls/cli/gcloud/sql/index.rb +66 -47
 - data/lib/souls/cli/index.rb +3 -20
 - data/lib/souls/cli/init/index.rb +140 -140
 - data/lib/souls/cli/release/release.rb +106 -105
 - data/lib/souls/cli/server/index.rb +12 -1
 - data/lib/souls/cli/sync/conf.rb +39 -38
 - data/lib/souls/cli/sync/model.rb +19 -20
 - data/lib/souls/cli/sync/pubsub.rb +69 -70
 - data/lib/souls/cli/upgrade/gemfile.rb +108 -0
 - data/lib/souls/cli/upgrade/index.rb +1 -1
 - data/lib/souls/cli.rb +57 -0
 - data/lib/souls/index.rb +1 -5
 - data/lib/souls/version.rb +1 -1
 - data/lib/souls/versions/.souls_api_version +1 -1
 - data/lib/souls/versions/.souls_worker_version +1 -1
 - data/lib/souls/worker/generate/index.rb +1 -1
 - data/lib/souls/worker/generate/job.rb +45 -0
 - data/lib/souls/worker/generate/mailer.rb +38 -43
 - data/lib/souls/worker/index.rb +3 -1
 - data/lib/souls.rb +2 -0
 - metadata +19 -5
 - data/lib/souls/api/generate/migration.rb +0 -51
 - data/lib/souls/cli/upgrade/gem_update.rb +0 -107
 - data/lib/souls/worker/generate/mutation.rb +0 -44
 
| 
         @@ -1,6 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module Souls
         
     | 
| 
       2 
     | 
    
         
            -
               
     | 
| 
       3 
     | 
    
         
            -
                 
     | 
| 
      
 2 
     | 
    
         
            +
              class Generate < Thor
         
     | 
| 
      
 3 
     | 
    
         
            +
                desc "edge [CLASS_NAME]", "Generate GraphQL Edge from schema.rb"
         
     | 
| 
      
 4 
     | 
    
         
            +
                def edge(class_name)
         
     | 
| 
       4 
5 
     | 
    
         
             
                  file_dir = "./app/graphql/types/edges"
         
     | 
| 
       5 
6 
     | 
    
         
             
                  FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
         
     | 
| 
       6 
7 
     | 
    
         
             
                  singularized_class_name = class_name.underscore.singularize
         
     | 
| 
         @@ -14,8 +15,8 @@ module Souls 
     | 
|
| 
       14 
15 
     | 
    
         
             
                  end
         
     | 
| 
       15 
16 
     | 
    
         
             
                  puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
         
     | 
| 
       16 
17 
     | 
    
         
             
                  file_path
         
     | 
| 
       17 
     | 
    
         
            -
                rescue  
     | 
| 
       18 
     | 
    
         
            -
                  raise( 
     | 
| 
      
 18 
     | 
    
         
            +
                rescue Thor::Error => e
         
     | 
| 
      
 19 
     | 
    
         
            +
                  raise(Thor::Error, e)
         
     | 
| 
       19 
20 
     | 
    
         
             
                end
         
     | 
| 
       20 
21 
     | 
    
         
             
              end
         
     | 
| 
       21 
22 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,18 +1,20 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module Souls
         
     | 
| 
       2 
     | 
    
         
            -
               
     | 
| 
       3 
     | 
    
         
            -
                 
     | 
| 
      
 2 
     | 
    
         
            +
              class Generate < Thor
         
     | 
| 
      
 3 
     | 
    
         
            +
                desc "manager [MANAGER_NAME]", "Generate GraphQL Mutation Template"
         
     | 
| 
      
 4 
     | 
    
         
            +
                method_option :mutation, aliases: "--mutation", required: true, desc: "Mutation File Name"
         
     | 
| 
      
 5 
     | 
    
         
            +
                def manager(class_name)
         
     | 
| 
       4 
6 
     | 
    
         
             
                  singularized_class_name = class_name.underscore.singularize
         
     | 
| 
       5 
7 
     | 
    
         
             
                  file_dir = "./app/graphql/mutations/managers/#{singularized_class_name}_manager"
         
     | 
| 
       6 
8 
     | 
    
         
             
                  FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
         
     | 
| 
       7 
     | 
    
         
            -
                  file_path = "#{file_dir}/#{mutation}.rb"
         
     | 
| 
      
 9 
     | 
    
         
            +
                  file_path = "#{file_dir}/#{options[:mutation]}.rb"
         
     | 
| 
       8 
10 
     | 
    
         
             
                  raise(StandardError, "Already Exist!") if File.exist?(file_path)
         
     | 
| 
       9 
11 
     | 
    
         | 
| 
       10 
12 
     | 
    
         
             
                  File.open(file_path, "w") do |f|
         
     | 
| 
       11 
13 
     | 
    
         
             
                    f.write(<<~TEXT)
         
     | 
| 
       12 
14 
     | 
    
         
             
                      module Mutations
         
     | 
| 
       13 
15 
     | 
    
         
             
                        module Managers::#{singularized_class_name.camelize}Manager
         
     | 
| 
       14 
     | 
    
         
            -
                          class #{mutation.underscore.camelize} < BaseMutation
         
     | 
| 
       15 
     | 
    
         
            -
                            description "#{mutation} description"
         
     | 
| 
      
 16 
     | 
    
         
            +
                          class #{options[:mutation].underscore.camelize} < BaseMutation
         
     | 
| 
      
 17 
     | 
    
         
            +
                            description "#{options[:mutation]} description"
         
     | 
| 
       16 
18 
     | 
    
         
             
                            ## Edit `argument` and `field`
         
     | 
| 
       17 
19 
     | 
    
         
             
                            argument :argment, String, required: true
         
     | 
| 
       18 
20 
     | 
    
         | 
| 
         @@ -30,8 +32,8 @@ module Souls 
     | 
|
| 
       30 
32 
     | 
    
         
             
                  end
         
     | 
| 
       31 
33 
     | 
    
         
             
                  puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
         
     | 
| 
       32 
34 
     | 
    
         
             
                  file_path
         
     | 
| 
       33 
     | 
    
         
            -
                rescue  
     | 
| 
       34 
     | 
    
         
            -
                  raise( 
     | 
| 
      
 35 
     | 
    
         
            +
                rescue Thor::Error => e
         
     | 
| 
      
 36 
     | 
    
         
            +
                  raise(Thor::Error, e)
         
     | 
| 
       35 
37 
     | 
    
         
             
                end
         
     | 
| 
       36 
38 
     | 
    
         
             
              end
         
     | 
| 
       37 
39 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,24 +1,22 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module Souls
         
     | 
| 
       2 
     | 
    
         
            -
               
     | 
| 
       3 
     | 
    
         
            -
                 
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
                   
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
                    return "Model already exist! #{file_path}" if File.exist?(file_path)
         
     | 
| 
      
 2 
     | 
    
         
            +
              class Generate < Thor
         
     | 
| 
      
 3 
     | 
    
         
            +
                desc "model [CLASS_NAME]", "Generate Model Template"
         
     | 
| 
      
 4 
     | 
    
         
            +
                def model(class_name)
         
     | 
| 
      
 5 
     | 
    
         
            +
                  file_dir = "./app/models/"
         
     | 
| 
      
 6 
     | 
    
         
            +
                  FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
         
     | 
| 
      
 7 
     | 
    
         
            +
                  file_path = "#{file_dir}#{class_name.singularize}.rb"
         
     | 
| 
      
 8 
     | 
    
         
            +
                  return "Model already exist! #{file_path}" if File.exist?(file_path)
         
     | 
| 
       10 
9 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
                    end
         
     | 
| 
       17 
     | 
    
         
            -
                    puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
         
     | 
| 
       18 
     | 
    
         
            -
                    file_path
         
     | 
| 
       19 
     | 
    
         
            -
                  rescue StandardError => e
         
     | 
| 
       20 
     | 
    
         
            -
                    raise(StandardError, e)
         
     | 
| 
      
 10 
     | 
    
         
            +
                  File.open(file_path, "w") do |f|
         
     | 
| 
      
 11 
     | 
    
         
            +
                    f.write(<<~TEXT)
         
     | 
| 
      
 12 
     | 
    
         
            +
                      class #{class_name.camelize} < ActiveRecord::Base
         
     | 
| 
      
 13 
     | 
    
         
            +
                      end
         
     | 
| 
      
 14 
     | 
    
         
            +
                    TEXT
         
     | 
| 
       21 
15 
     | 
    
         
             
                  end
         
     | 
| 
      
 16 
     | 
    
         
            +
                  puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
         
     | 
| 
      
 17 
     | 
    
         
            +
                  file_path
         
     | 
| 
      
 18 
     | 
    
         
            +
                rescue Thor::Error => e
         
     | 
| 
      
 19 
     | 
    
         
            +
                  raise(Thor::Error, e)
         
     | 
| 
       22 
20 
     | 
    
         
             
                end
         
     | 
| 
       23 
21 
     | 
    
         
             
              end
         
     | 
| 
       24 
22 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,288 +1,287 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module Souls
         
     | 
| 
       2 
     | 
    
         
            -
               
     | 
| 
       3 
     | 
    
         
            -
                 
     | 
| 
       4 
     | 
    
         
            -
                 
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
                   
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
                    file_path = "./app/graphql/mutations/base/#{singularized_class_name}/create_#{singularized_class_name}.rb"
         
     | 
| 
       11 
     | 
    
         
            -
                    File.open(file_path, "w") do |new_line|
         
     | 
| 
       12 
     | 
    
         
            -
                      new_line.write(<<~TEXT)
         
     | 
| 
       13 
     | 
    
         
            -
                        module Mutations
         
     | 
| 
       14 
     | 
    
         
            -
                          module Base::#{singularized_class_name.camelize}
         
     | 
| 
       15 
     | 
    
         
            -
                            class Create#{singularized_class_name.camelize} < BaseMutation
         
     | 
| 
       16 
     | 
    
         
            -
                              field :#{singularized_class_name}_edge, Types::#{singularized_class_name.camelize}Type.edge_type, null: false
         
     | 
| 
       17 
     | 
    
         
            -
                              field :error, String, null: true
         
     | 
| 
      
 2 
     | 
    
         
            +
              class Generate < Thor
         
     | 
| 
      
 3 
     | 
    
         
            +
                desc "mutation [CLASS_NAME]", "Generate GraphQL Mutation from schema.rb"
         
     | 
| 
      
 4 
     | 
    
         
            +
                def mutation(class_name)
         
     | 
| 
      
 5 
     | 
    
         
            +
                  singularized_class_name = class_name.singularize
         
     | 
| 
      
 6 
     | 
    
         
            +
                  file_dir = "./app/graphql/mutations/base"
         
     | 
| 
      
 7 
     | 
    
         
            +
                  FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
         
     | 
| 
      
 8 
     | 
    
         
            +
                  file_path = "./app/graphql/mutations/base/#{singularized_class_name}/create_#{singularized_class_name}.rb"
         
     | 
| 
      
 9 
     | 
    
         
            +
                  return "Mutation already exist! #{file_path}" if File.exist?(file_path)
         
     | 
| 
       18 
10 
     | 
    
         | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
      
 11 
     | 
    
         
            +
                  create_mutation_head(class_name: singularized_class_name)
         
     | 
| 
      
 12 
     | 
    
         
            +
                  relation_params = create_mutation_params(class_name: singularized_class_name)
         
     | 
| 
      
 13 
     | 
    
         
            +
                  create_mutation_after_params(class_name: singularized_class_name, relation_params: relation_params)
         
     | 
| 
      
 14 
     | 
    
         
            +
                  create_mutation_end(class_name: singularized_class_name)
         
     | 
| 
      
 15 
     | 
    
         
            +
                  update_mutation(class_name: singularized_class_name)
         
     | 
| 
      
 16 
     | 
    
         
            +
                  delete_mutation(class_name: singularized_class_name)
         
     | 
| 
      
 17 
     | 
    
         
            +
                  destroy_delete_mutation(class_name: singularized_class_name)
         
     | 
| 
      
 18 
     | 
    
         
            +
                  puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
         
     | 
| 
      
 19 
     | 
    
         
            +
                  file_path
         
     | 
| 
      
 20 
     | 
    
         
            +
                rescue Thor::Error => e
         
     | 
| 
      
 21 
     | 
    
         
            +
                  raise(Thor::Error, e)
         
     | 
| 
      
 22 
     | 
    
         
            +
                end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                private
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                def create_mutation_head(class_name: "user")
         
     | 
| 
      
 27 
     | 
    
         
            +
                  singularized_class_name = class_name.singularize.underscore
         
     | 
| 
      
 28 
     | 
    
         
            +
                  dir_name = "./app/graphql/mutations/base/#{singularized_class_name}"
         
     | 
| 
      
 29 
     | 
    
         
            +
                  FileUtils.mkdir_p(dir_name) unless Dir.exist?(dir_name)
         
     | 
| 
      
 30 
     | 
    
         
            +
                  file_path = "./app/graphql/mutations/base/#{singularized_class_name}/create_#{singularized_class_name}.rb"
         
     | 
| 
      
 31 
     | 
    
         
            +
                  File.open(file_path, "w") do |new_line|
         
     | 
| 
      
 32 
     | 
    
         
            +
                    new_line.write(<<~TEXT)
         
     | 
| 
      
 33 
     | 
    
         
            +
                      module Mutations
         
     | 
| 
      
 34 
     | 
    
         
            +
                        module Base::#{singularized_class_name.camelize}
         
     | 
| 
      
 35 
     | 
    
         
            +
                          class Create#{singularized_class_name.camelize} < BaseMutation
         
     | 
| 
      
 36 
     | 
    
         
            +
                            field :#{singularized_class_name}_edge, Types::#{singularized_class_name.camelize}Type.edge_type, null: false
         
     | 
| 
      
 37 
     | 
    
         
            +
                            field :error, String, null: true
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                    TEXT
         
     | 
| 
       22 
40 
     | 
    
         
             
                  end
         
     | 
| 
      
 41 
     | 
    
         
            +
                  file_path
         
     | 
| 
      
 42 
     | 
    
         
            +
                end
         
     | 
| 
       23 
43 
     | 
    
         | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
      
 44 
     | 
    
         
            +
                def create_mutation_params(class_name: "user")
         
     | 
| 
      
 45 
     | 
    
         
            +
                  file_path = "./app/graphql/mutations/base/#{class_name}/create_#{class_name}.rb"
         
     | 
| 
      
 46 
     | 
    
         
            +
                  path = "./db/schema.rb"
         
     | 
| 
      
 47 
     | 
    
         
            +
                  @on = false
         
     | 
| 
      
 48 
     | 
    
         
            +
                  @user_exist = false
         
     | 
| 
      
 49 
     | 
    
         
            +
                  @relation_params = []
         
     | 
| 
      
 50 
     | 
    
         
            +
                  File.open(file_path, "a") do |new_line|
         
     | 
| 
      
 51 
     | 
    
         
            +
                    File.open(path, "r") do |f|
         
     | 
| 
      
 52 
     | 
    
         
            +
                      f.each_line.with_index do |line, _i|
         
     | 
| 
      
 53 
     | 
    
         
            +
                        if @on
         
     | 
| 
      
 54 
     | 
    
         
            +
                          if line.include?("t.index") || line.strip == "end"
         
     | 
| 
      
 55 
     | 
    
         
            +
                            if @user_exist
         
     | 
| 
      
 56 
     | 
    
         
            +
                              new_line.write(<<-TEXT)
         
     | 
| 
       37 
57 
     | 
    
         | 
| 
       38 
58 
     | 
    
         
             
                  def resolve **args
         
     | 
| 
       39 
59 
     | 
    
         
             
                    args[:user_id] = context[:user].id
         
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
      
 60 
     | 
    
         
            +
                              TEXT
         
     | 
| 
      
 61 
     | 
    
         
            +
                            else
         
     | 
| 
      
 62 
     | 
    
         
            +
                              new_line.write(<<-TEXT)
         
     | 
| 
       43 
63 
     | 
    
         | 
| 
       44 
64 
     | 
    
         
             
                  def resolve **args
         
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
                              end
         
     | 
| 
       47 
     | 
    
         
            -
                              break
         
     | 
| 
       48 
     | 
    
         
            -
                            end
         
     | 
| 
       49 
     | 
    
         
            -
                            field = "[String]" if line.include?("array: true")
         
     | 
| 
       50 
     | 
    
         
            -
                            type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
         
     | 
| 
       51 
     | 
    
         
            -
                            field ||= Souls.type_check(type)
         
     | 
| 
       52 
     | 
    
         
            -
                            case name
         
     | 
| 
       53 
     | 
    
         
            -
                            when "user_id"
         
     | 
| 
       54 
     | 
    
         
            -
                              @user_exist = true
         
     | 
| 
       55 
     | 
    
         
            -
                            when /$*_id\z/
         
     | 
| 
       56 
     | 
    
         
            -
                              @relation_params << name
         
     | 
| 
       57 
     | 
    
         
            -
                              new_line.write("      argument :#{name}, String, required: false\n")
         
     | 
| 
       58 
     | 
    
         
            -
                            when "created_at", "updated_at"
         
     | 
| 
       59 
     | 
    
         
            -
                              next
         
     | 
| 
       60 
     | 
    
         
            -
                            else
         
     | 
| 
       61 
     | 
    
         
            -
                              new_line.write("      argument :#{name}, #{field}, required: false\n")
         
     | 
| 
      
 65 
     | 
    
         
            +
                              TEXT
         
     | 
| 
       62 
66 
     | 
    
         
             
                            end
         
     | 
| 
      
 67 
     | 
    
         
            +
                            break
         
     | 
| 
      
 68 
     | 
    
         
            +
                          end
         
     | 
| 
      
 69 
     | 
    
         
            +
                          field = "[String]" if line.include?("array: true")
         
     | 
| 
      
 70 
     | 
    
         
            +
                          type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
         
     | 
| 
      
 71 
     | 
    
         
            +
                          field ||= Souls.type_check(type)
         
     | 
| 
      
 72 
     | 
    
         
            +
                          case name
         
     | 
| 
      
 73 
     | 
    
         
            +
                          when "user_id"
         
     | 
| 
      
 74 
     | 
    
         
            +
                            @user_exist = true
         
     | 
| 
      
 75 
     | 
    
         
            +
                          when /$*_id\z/
         
     | 
| 
      
 76 
     | 
    
         
            +
                            @relation_params << name
         
     | 
| 
      
 77 
     | 
    
         
            +
                            new_line.write("      argument :#{name}, String, required: false\n")
         
     | 
| 
      
 78 
     | 
    
         
            +
                          when "created_at", "updated_at"
         
     | 
| 
      
 79 
     | 
    
         
            +
                            next
         
     | 
| 
      
 80 
     | 
    
         
            +
                          else
         
     | 
| 
      
 81 
     | 
    
         
            +
                            new_line.write("      argument :#{name}, #{field}, required: false\n")
         
     | 
| 
       63 
82 
     | 
    
         
             
                          end
         
     | 
| 
       64 
     | 
    
         
            -
                          @on = true if Souls.table_check(line: line, class_name: class_name)
         
     | 
| 
       65 
83 
     | 
    
         
             
                        end
         
     | 
| 
      
 84 
     | 
    
         
            +
                        @on = true if Souls.table_check(line: line, class_name: class_name)
         
     | 
| 
       66 
85 
     | 
    
         
             
                      end
         
     | 
| 
       67 
86 
     | 
    
         
             
                    end
         
     | 
| 
       68 
     | 
    
         
            -
                    @relation_params
         
     | 
| 
       69 
87 
     | 
    
         
             
                  end
         
     | 
| 
      
 88 
     | 
    
         
            +
                  @relation_params
         
     | 
| 
      
 89 
     | 
    
         
            +
                end
         
     | 
| 
       70 
90 
     | 
    
         | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
      
 91 
     | 
    
         
            +
                def create_mutation_after_params(class_name: "user", relation_params: [])
         
     | 
| 
      
 92 
     | 
    
         
            +
                  return false if relation_params.empty?
         
     | 
| 
       73 
93 
     | 
    
         | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
                      end
         
     | 
| 
      
 94 
     | 
    
         
            +
                  file_path = "./app/graphql/mutations/base/#{class_name}/create_#{class_name}.rb"
         
     | 
| 
      
 95 
     | 
    
         
            +
                  relation_params.each do |params_name|
         
     | 
| 
      
 96 
     | 
    
         
            +
                    File.open(file_path, "a") do |new_line|
         
     | 
| 
      
 97 
     | 
    
         
            +
                      new_line.write("        _, args[:#{params_name}] = SoulsApiSchema.from_global_id(args[:#{params_name}])\n")
         
     | 
| 
       79 
98 
     | 
    
         
             
                    end
         
     | 
| 
       80 
     | 
    
         
            -
                    true
         
     | 
| 
       81 
99 
     | 
    
         
             
                  end
         
     | 
| 
      
 100 
     | 
    
         
            +
                  true
         
     | 
| 
      
 101 
     | 
    
         
            +
                end
         
     | 
| 
       82 
102 
     | 
    
         | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
       86 
     | 
    
         
            -
             
     | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
      
 103 
     | 
    
         
            +
                def create_mutation_end(class_name: "user")
         
     | 
| 
      
 104 
     | 
    
         
            +
                  file_path = "./app/graphql/mutations/base/#{class_name}/create_#{class_name}.rb"
         
     | 
| 
      
 105 
     | 
    
         
            +
                  File.open(file_path, "a") do |new_line|
         
     | 
| 
      
 106 
     | 
    
         
            +
                    new_line.write(<<~TEXT)
         
     | 
| 
      
 107 
     | 
    
         
            +
                              data = ::#{class_name.camelize}.new args
         
     | 
| 
      
 108 
     | 
    
         
            +
                              raise(StandardError, data.errors.full_messages) unless data.save
         
     | 
| 
       89 
109 
     | 
    
         | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
     | 
    
         
            -
                              end
         
     | 
| 
      
 110 
     | 
    
         
            +
                              { #{class_name}_edge: { node: data } }
         
     | 
| 
      
 111 
     | 
    
         
            +
                            rescue StandardError => error
         
     | 
| 
      
 112 
     | 
    
         
            +
                              GraphQL::ExecutionError.new error
         
     | 
| 
       94 
113 
     | 
    
         
             
                            end
         
     | 
| 
       95 
114 
     | 
    
         
             
                          end
         
     | 
| 
       96 
115 
     | 
    
         
             
                        end
         
     | 
| 
       97 
     | 
    
         
            -
                       
     | 
| 
       98 
     | 
    
         
            -
                     
     | 
| 
       99 
     | 
    
         
            -
                    file_path
         
     | 
| 
      
 116 
     | 
    
         
            +
                      end
         
     | 
| 
      
 117 
     | 
    
         
            +
                    TEXT
         
     | 
| 
       100 
118 
     | 
    
         
             
                  end
         
     | 
| 
      
 119 
     | 
    
         
            +
                  file_path
         
     | 
| 
      
 120 
     | 
    
         
            +
                end
         
     | 
| 
       101 
121 
     | 
    
         | 
| 
       102 
     | 
    
         
            -
             
     | 
| 
       103 
     | 
    
         
            -
             
     | 
| 
       104 
     | 
    
         
            -
             
     | 
| 
       105 
     | 
    
         
            -
             
     | 
| 
       106 
     | 
    
         
            -
             
     | 
| 
       107 
     | 
    
         
            -
             
     | 
| 
       108 
     | 
    
         
            -
             
     | 
| 
       109 
     | 
    
         
            -
             
     | 
| 
       110 
     | 
    
         
            -
             
     | 
| 
      
 122 
     | 
    
         
            +
                ## 2.Mutation - Update
         
     | 
| 
      
 123 
     | 
    
         
            +
                def update_mutation_head(class_name: "user")
         
     | 
| 
      
 124 
     | 
    
         
            +
                  file_path = "./app/graphql/mutations/base/#{class_name}/update_#{class_name}.rb"
         
     | 
| 
      
 125 
     | 
    
         
            +
                  File.open(file_path, "w") do |new_line|
         
     | 
| 
      
 126 
     | 
    
         
            +
                    new_line.write(<<~TEXT)
         
     | 
| 
      
 127 
     | 
    
         
            +
                      module Mutations
         
     | 
| 
      
 128 
     | 
    
         
            +
                        module Base::#{class_name.camelize}
         
     | 
| 
      
 129 
     | 
    
         
            +
                          class Update#{class_name.camelize} < BaseMutation
         
     | 
| 
      
 130 
     | 
    
         
            +
                            field :#{class_name}_edge, Types::#{class_name.camelize}Type.edge_type, null: false
         
     | 
| 
       111 
131 
     | 
    
         | 
| 
       112 
     | 
    
         
            -
             
     | 
| 
       113 
     | 
    
         
            -
             
     | 
| 
       114 
     | 
    
         
            -
                    end
         
     | 
| 
       115 
     | 
    
         
            -
                    file_path
         
     | 
| 
      
 132 
     | 
    
         
            +
                            argument :id, String, required: true
         
     | 
| 
      
 133 
     | 
    
         
            +
                    TEXT
         
     | 
| 
       116 
134 
     | 
    
         
             
                  end
         
     | 
| 
      
 135 
     | 
    
         
            +
                  file_path
         
     | 
| 
      
 136 
     | 
    
         
            +
                end
         
     | 
| 
       117 
137 
     | 
    
         | 
| 
       118 
     | 
    
         
            -
             
     | 
| 
       119 
     | 
    
         
            -
             
     | 
| 
       120 
     | 
    
         
            -
             
     | 
| 
       121 
     | 
    
         
            -
             
     | 
| 
       122 
     | 
    
         
            -
             
     | 
| 
       123 
     | 
    
         
            -
             
     | 
| 
       124 
     | 
    
         
            -
             
     | 
| 
       125 
     | 
    
         
            -
             
     | 
| 
       126 
     | 
    
         
            -
             
     | 
| 
       127 
     | 
    
         
            -
             
     | 
| 
       128 
     | 
    
         
            -
             
     | 
| 
       129 
     | 
    
         
            -
             
     | 
| 
       130 
     | 
    
         
            -
             
     | 
| 
      
 138 
     | 
    
         
            +
                def update_mutation_params(class_name: "user")
         
     | 
| 
      
 139 
     | 
    
         
            +
                  file_path = "./app/graphql/mutations/base/#{class_name}/update_#{class_name}.rb"
         
     | 
| 
      
 140 
     | 
    
         
            +
                  path = "./db/schema.rb"
         
     | 
| 
      
 141 
     | 
    
         
            +
                  @on = false
         
     | 
| 
      
 142 
     | 
    
         
            +
                  @user_exist = false
         
     | 
| 
      
 143 
     | 
    
         
            +
                  @relation_params = []
         
     | 
| 
      
 144 
     | 
    
         
            +
                  File.open(file_path, "a") do |new_line|
         
     | 
| 
      
 145 
     | 
    
         
            +
                    File.open(path, "r") do |f|
         
     | 
| 
      
 146 
     | 
    
         
            +
                      f.each_line.with_index do |line, _i|
         
     | 
| 
      
 147 
     | 
    
         
            +
                        if @on
         
     | 
| 
      
 148 
     | 
    
         
            +
                          if line.include?("t.index") || line.strip == "end"
         
     | 
| 
      
 149 
     | 
    
         
            +
                            if @user_exist
         
     | 
| 
      
 150 
     | 
    
         
            +
                              new_line.write(<<-TEXT)
         
     | 
| 
       131 
151 
     | 
    
         | 
| 
       132 
152 
     | 
    
         
             
                  def resolve **args
         
     | 
| 
       133 
153 
     | 
    
         
             
                    args[:user_id] = context[:user].id
         
     | 
| 
       134 
154 
     | 
    
         
             
                    _, args[:id] = SoulsApiSchema.from_global_id(args[:id])
         
     | 
| 
       135 
     | 
    
         
            -
             
     | 
| 
       136 
     | 
    
         
            -
             
     | 
| 
       137 
     | 
    
         
            -
             
     | 
| 
      
 155 
     | 
    
         
            +
                              TEXT
         
     | 
| 
      
 156 
     | 
    
         
            +
                            else
         
     | 
| 
      
 157 
     | 
    
         
            +
                              new_line.write(<<-TEXT)
         
     | 
| 
       138 
158 
     | 
    
         | 
| 
       139 
159 
     | 
    
         
             
                  def resolve **args
         
     | 
| 
       140 
160 
     | 
    
         
             
                    _, args[:id] = SoulsApiSchema.from_global_id(args[:id])
         
     | 
| 
       141 
     | 
    
         
            -
             
     | 
| 
       142 
     | 
    
         
            -
                              end
         
     | 
| 
       143 
     | 
    
         
            -
                              break
         
     | 
| 
       144 
     | 
    
         
            -
                            end
         
     | 
| 
       145 
     | 
    
         
            -
                            field = "[String]" if line.include?("array: true")
         
     | 
| 
       146 
     | 
    
         
            -
                            type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
         
     | 
| 
       147 
     | 
    
         
            -
                            field ||= Souls.type_check(type)
         
     | 
| 
       148 
     | 
    
         
            -
                            case name
         
     | 
| 
       149 
     | 
    
         
            -
                            when "user_id"
         
     | 
| 
       150 
     | 
    
         
            -
                              @user_exist = true
         
     | 
| 
       151 
     | 
    
         
            -
                            when /$*_id\z/
         
     | 
| 
       152 
     | 
    
         
            -
                              @relation_params << name
         
     | 
| 
       153 
     | 
    
         
            -
                              new_line.write("      argument :#{name}, String, required: false\n")
         
     | 
| 
       154 
     | 
    
         
            -
                            when "created_at", "updated_at"
         
     | 
| 
       155 
     | 
    
         
            -
                              next
         
     | 
| 
       156 
     | 
    
         
            -
                            else
         
     | 
| 
       157 
     | 
    
         
            -
                              new_line.write("      argument :#{name}, #{field}, required: false\n")
         
     | 
| 
      
 161 
     | 
    
         
            +
                              TEXT
         
     | 
| 
       158 
162 
     | 
    
         
             
                            end
         
     | 
| 
      
 163 
     | 
    
         
            +
                            break
         
     | 
| 
      
 164 
     | 
    
         
            +
                          end
         
     | 
| 
      
 165 
     | 
    
         
            +
                          field = "[String]" if line.include?("array: true")
         
     | 
| 
      
 166 
     | 
    
         
            +
                          type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
         
     | 
| 
      
 167 
     | 
    
         
            +
                          field ||= Souls.type_check(type)
         
     | 
| 
      
 168 
     | 
    
         
            +
                          case name
         
     | 
| 
      
 169 
     | 
    
         
            +
                          when "user_id"
         
     | 
| 
      
 170 
     | 
    
         
            +
                            @user_exist = true
         
     | 
| 
      
 171 
     | 
    
         
            +
                          when /$*_id\z/
         
     | 
| 
      
 172 
     | 
    
         
            +
                            @relation_params << name
         
     | 
| 
      
 173 
     | 
    
         
            +
                            new_line.write("      argument :#{name}, String, required: false\n")
         
     | 
| 
      
 174 
     | 
    
         
            +
                          when "created_at", "updated_at"
         
     | 
| 
      
 175 
     | 
    
         
            +
                            next
         
     | 
| 
      
 176 
     | 
    
         
            +
                          else
         
     | 
| 
      
 177 
     | 
    
         
            +
                            new_line.write("      argument :#{name}, #{field}, required: false\n")
         
     | 
| 
       159 
178 
     | 
    
         
             
                          end
         
     | 
| 
       160 
     | 
    
         
            -
                          @on = true if Souls.table_check(line: line, class_name: class_name)
         
     | 
| 
       161 
179 
     | 
    
         
             
                        end
         
     | 
| 
      
 180 
     | 
    
         
            +
                        @on = true if Souls.table_check(line: line, class_name: class_name)
         
     | 
| 
       162 
181 
     | 
    
         
             
                      end
         
     | 
| 
       163 
182 
     | 
    
         
             
                    end
         
     | 
| 
       164 
     | 
    
         
            -
                    @relation_params
         
     | 
| 
       165 
183 
     | 
    
         
             
                  end
         
     | 
| 
      
 184 
     | 
    
         
            +
                  @relation_params
         
     | 
| 
      
 185 
     | 
    
         
            +
                end
         
     | 
| 
       166 
186 
     | 
    
         | 
| 
       167 
     | 
    
         
            -
             
     | 
| 
       168 
     | 
    
         
            -
             
     | 
| 
      
 187 
     | 
    
         
            +
                def update_mutation_after_params(class_name: "article", relation_params: [])
         
     | 
| 
      
 188 
     | 
    
         
            +
                  return false if relation_params.empty?
         
     | 
| 
       169 
189 
     | 
    
         | 
| 
       170 
     | 
    
         
            -
             
     | 
| 
       171 
     | 
    
         
            -
             
     | 
| 
       172 
     | 
    
         
            -
             
     | 
| 
       173 
     | 
    
         
            -
             
     | 
| 
       174 
     | 
    
         
            -
                      end
         
     | 
| 
      
 190 
     | 
    
         
            +
                  file_path = "./app/graphql/mutations/base/#{class_name}/update_#{class_name}.rb"
         
     | 
| 
      
 191 
     | 
    
         
            +
                  relation_params.each do |params_name|
         
     | 
| 
      
 192 
     | 
    
         
            +
                    File.open(file_path, "a") do |new_line|
         
     | 
| 
      
 193 
     | 
    
         
            +
                      new_line.write("        _, args[:#{params_name}] = SoulsApiSchema.from_global_id(args[:#{params_name}])\n")
         
     | 
| 
       175 
194 
     | 
    
         
             
                    end
         
     | 
| 
       176 
     | 
    
         
            -
                    true
         
     | 
| 
       177 
195 
     | 
    
         
             
                  end
         
     | 
| 
      
 196 
     | 
    
         
            +
                  true
         
     | 
| 
      
 197 
     | 
    
         
            +
                end
         
     | 
| 
       178 
198 
     | 
    
         | 
| 
       179 
     | 
    
         
            -
             
     | 
| 
       180 
     | 
    
         
            -
             
     | 
| 
       181 
     | 
    
         
            -
             
     | 
| 
       182 
     | 
    
         
            -
             
     | 
| 
       183 
     | 
    
         
            -
             
     | 
| 
       184 
     | 
    
         
            -
             
     | 
| 
       185 
     | 
    
         
            -
             
     | 
| 
       186 
     | 
    
         
            -
             
     | 
| 
       187 
     | 
    
         
            -
             
     | 
| 
       188 
     | 
    
         
            -
                              end
         
     | 
| 
      
 199 
     | 
    
         
            +
                def update_mutation_end(class_name: "user")
         
     | 
| 
      
 200 
     | 
    
         
            +
                  file_path = "./app/graphql/mutations/base/#{class_name}/update_#{class_name}.rb"
         
     | 
| 
      
 201 
     | 
    
         
            +
                  File.open(file_path, "a") do |new_line|
         
     | 
| 
      
 202 
     | 
    
         
            +
                    new_line.write(<<~TEXT)
         
     | 
| 
      
 203 
     | 
    
         
            +
                              #{class_name} = ::#{class_name.camelize}.find args[:id]
         
     | 
| 
      
 204 
     | 
    
         
            +
                              #{class_name}.update args
         
     | 
| 
      
 205 
     | 
    
         
            +
                              { #{class_name}_edge: { node: ::#{class_name.camelize}.find(args[:id]) } }
         
     | 
| 
      
 206 
     | 
    
         
            +
                            rescue StandardError => error
         
     | 
| 
      
 207 
     | 
    
         
            +
                              GraphQL::ExecutionError.new error
         
     | 
| 
       189 
208 
     | 
    
         
             
                            end
         
     | 
| 
       190 
209 
     | 
    
         
             
                          end
         
     | 
| 
       191 
210 
     | 
    
         
             
                        end
         
     | 
| 
       192 
     | 
    
         
            -
                       
     | 
| 
       193 
     | 
    
         
            -
                     
     | 
| 
       194 
     | 
    
         
            -
                    file_path
         
     | 
| 
      
 211 
     | 
    
         
            +
                      end
         
     | 
| 
      
 212 
     | 
    
         
            +
                    TEXT
         
     | 
| 
       195 
213 
     | 
    
         
             
                  end
         
     | 
| 
      
 214 
     | 
    
         
            +
                  file_path
         
     | 
| 
      
 215 
     | 
    
         
            +
                end
         
     | 
| 
       196 
216 
     | 
    
         | 
| 
       197 
     | 
    
         
            -
             
     | 
| 
       198 
     | 
    
         
            -
             
     | 
| 
       199 
     | 
    
         
            -
             
     | 
| 
      
 217 
     | 
    
         
            +
                def update_mutation(class_name: "user")
         
     | 
| 
      
 218 
     | 
    
         
            +
                  file_path = "./app/graphql/mutations/base/#{class_name}/update_#{class_name}.rb"
         
     | 
| 
      
 219 
     | 
    
         
            +
                  return "Mutation already exist! #{file_path}" if File.exist?(file_path)
         
     | 
| 
       200 
220 
     | 
    
         | 
| 
       201 
     | 
    
         
            -
             
     | 
| 
       202 
     | 
    
         
            -
             
     | 
| 
       203 
     | 
    
         
            -
             
     | 
| 
       204 
     | 
    
         
            -
             
     | 
| 
       205 
     | 
    
         
            -
             
     | 
| 
      
 221 
     | 
    
         
            +
                  update_mutation_head(class_name: class_name)
         
     | 
| 
      
 222 
     | 
    
         
            +
                  relation_params = update_mutation_params(class_name: class_name)
         
     | 
| 
      
 223 
     | 
    
         
            +
                  update_mutation_after_params(class_name: class_name, relation_params: relation_params)
         
     | 
| 
      
 224 
     | 
    
         
            +
                  update_mutation_end(class_name: class_name)
         
     | 
| 
      
 225 
     | 
    
         
            +
                end
         
     | 
| 
       206 
226 
     | 
    
         | 
| 
       207 
     | 
    
         
            -
             
     | 
| 
       208 
     | 
    
         
            -
             
     | 
| 
       209 
     | 
    
         
            -
             
     | 
| 
       210 
     | 
    
         
            -
             
     | 
| 
      
 227 
     | 
    
         
            +
                # 3. Mutation - Delete
         
     | 
| 
      
 228 
     | 
    
         
            +
                def delete_mutation(class_name: "user")
         
     | 
| 
      
 229 
     | 
    
         
            +
                  file_path = "./app/graphql/mutations/base/#{class_name}/delete_#{class_name}.rb"
         
     | 
| 
      
 230 
     | 
    
         
            +
                  return "Mutation already exist! #{file_path}" if File.exist?(file_path)
         
     | 
| 
       211 
231 
     | 
    
         | 
| 
       212 
     | 
    
         
            -
             
     | 
| 
       213 
     | 
    
         
            -
             
     | 
| 
       214 
     | 
    
         
            -
             
     | 
| 
       215 
     | 
    
         
            -
             
     | 
| 
       216 
     | 
    
         
            -
             
     | 
| 
       217 
     | 
    
         
            -
             
     | 
| 
       218 
     | 
    
         
            -
             
     | 
| 
      
 232 
     | 
    
         
            +
                  File.open(file_path, "w") do |f|
         
     | 
| 
      
 233 
     | 
    
         
            +
                    f.write(<<~TEXT)
         
     | 
| 
      
 234 
     | 
    
         
            +
                      module Mutations
         
     | 
| 
      
 235 
     | 
    
         
            +
                        module Base::#{class_name.camelize}
         
     | 
| 
      
 236 
     | 
    
         
            +
                          class Delete#{class_name.camelize} < BaseMutation
         
     | 
| 
      
 237 
     | 
    
         
            +
                            field :#{class_name}, Types::#{class_name.camelize}Type, null: false
         
     | 
| 
      
 238 
     | 
    
         
            +
                            argument :id, String, required: true
         
     | 
| 
       219 
239 
     | 
    
         | 
| 
       220 
     | 
    
         
            -
             
     | 
| 
       221 
     | 
    
         
            -
             
     | 
| 
       222 
     | 
    
         
            -
             
     | 
| 
       223 
     | 
    
         
            -
             
     | 
| 
       224 
     | 
    
         
            -
             
     | 
| 
       225 
     | 
    
         
            -
             
     | 
| 
       226 
     | 
    
         
            -
             
     | 
| 
       227 
     | 
    
         
            -
                              end
         
     | 
| 
      
 240 
     | 
    
         
            +
                            def resolve **args
         
     | 
| 
      
 241 
     | 
    
         
            +
                              _, data_id = SoulsApiSchema.from_global_id args[:id]
         
     | 
| 
      
 242 
     | 
    
         
            +
                              #{class_name} = ::#{class_name.camelize}.find data_id
         
     | 
| 
      
 243 
     | 
    
         
            +
                              #{class_name}.update(is_deleted: true)
         
     | 
| 
      
 244 
     | 
    
         
            +
                              { #{class_name}: ::#{class_name.camelize}.find(data_id) }
         
     | 
| 
      
 245 
     | 
    
         
            +
                            rescue StandardError => error
         
     | 
| 
      
 246 
     | 
    
         
            +
                              GraphQL::ExecutionError.new error
         
     | 
| 
       228 
247 
     | 
    
         
             
                            end
         
     | 
| 
       229 
248 
     | 
    
         
             
                          end
         
     | 
| 
       230 
249 
     | 
    
         
             
                        end
         
     | 
| 
       231 
     | 
    
         
            -
                       
     | 
| 
       232 
     | 
    
         
            -
                     
     | 
| 
       233 
     | 
    
         
            -
                    file_path
         
     | 
| 
      
 250 
     | 
    
         
            +
                      end
         
     | 
| 
      
 251 
     | 
    
         
            +
                    TEXT
         
     | 
| 
       234 
252 
     | 
    
         
             
                  end
         
     | 
| 
      
 253 
     | 
    
         
            +
                  file_path
         
     | 
| 
      
 254 
     | 
    
         
            +
                end
         
     | 
| 
       235 
255 
     | 
    
         | 
| 
       236 
     | 
    
         
            -
             
     | 
| 
       237 
     | 
    
         
            -
             
     | 
| 
       238 
     | 
    
         
            -
             
     | 
| 
       239 
     | 
    
         
            -
             
     | 
| 
      
 256 
     | 
    
         
            +
                # 4. Mutation - Destroy Delete
         
     | 
| 
      
 257 
     | 
    
         
            +
                def destroy_delete_mutation(class_name: "user")
         
     | 
| 
      
 258 
     | 
    
         
            +
                  file_path = "./app/graphql/mutations/base/#{class_name}/destroy_delete_#{class_name}.rb"
         
     | 
| 
      
 259 
     | 
    
         
            +
                  return "Mutation already exist! #{file_path}" if File.exist?(file_path)
         
     | 
| 
       240 
260 
     | 
    
         | 
| 
       241 
     | 
    
         
            -
             
     | 
| 
       242 
     | 
    
         
            -
             
     | 
| 
       243 
     | 
    
         
            -
             
     | 
| 
       244 
     | 
    
         
            -
             
     | 
| 
       245 
     | 
    
         
            -
             
     | 
| 
       246 
     | 
    
         
            -
             
     | 
| 
       247 
     | 
    
         
            -
             
     | 
| 
      
 261 
     | 
    
         
            +
                  File.open(file_path, "w") do |f|
         
     | 
| 
      
 262 
     | 
    
         
            +
                    f.write(<<~TEXT)
         
     | 
| 
      
 263 
     | 
    
         
            +
                      module Mutations
         
     | 
| 
      
 264 
     | 
    
         
            +
                        module Base::#{class_name.camelize}
         
     | 
| 
      
 265 
     | 
    
         
            +
                          class DestroyDelete#{class_name.camelize} < BaseMutation
         
     | 
| 
      
 266 
     | 
    
         
            +
                            field :#{class_name}, Types::#{class_name.camelize}Type, null: false
         
     | 
| 
      
 267 
     | 
    
         
            +
                            argument :id, String, required: true
         
     | 
| 
       248 
268 
     | 
    
         | 
| 
       249 
     | 
    
         
            -
             
     | 
| 
       250 
     | 
    
         
            -
             
     | 
| 
       251 
     | 
    
         
            -
             
     | 
| 
       252 
     | 
    
         
            -
             
     | 
| 
       253 
     | 
    
         
            -
             
     | 
| 
       254 
     | 
    
         
            -
             
     | 
| 
       255 
     | 
    
         
            -
             
     | 
| 
       256 
     | 
    
         
            -
                              end
         
     | 
| 
      
 269 
     | 
    
         
            +
                            def resolve **args
         
     | 
| 
      
 270 
     | 
    
         
            +
                              _, data_id = SoulsApiSchema.from_global_id args[:id]
         
     | 
| 
      
 271 
     | 
    
         
            +
                              #{class_name} = ::#{class_name.camelize}.find data_id
         
     | 
| 
      
 272 
     | 
    
         
            +
                              #{class_name}.destroy
         
     | 
| 
      
 273 
     | 
    
         
            +
                              { #{class_name}: #{class_name} }
         
     | 
| 
      
 274 
     | 
    
         
            +
                            rescue StandardError => error
         
     | 
| 
      
 275 
     | 
    
         
            +
                              GraphQL::ExecutionError.new error
         
     | 
| 
       257 
276 
     | 
    
         
             
                            end
         
     | 
| 
       258 
277 
     | 
    
         
             
                          end
         
     | 
| 
       259 
278 
     | 
    
         
             
                        end
         
     | 
| 
       260 
     | 
    
         
            -
                       
     | 
| 
       261 
     | 
    
         
            -
                     
     | 
| 
       262 
     | 
    
         
            -
                    file_path
         
     | 
| 
       263 
     | 
    
         
            -
                  rescue StandardError => e
         
     | 
| 
       264 
     | 
    
         
            -
                    puts(e)
         
     | 
| 
       265 
     | 
    
         
            -
                  end
         
     | 
| 
       266 
     | 
    
         
            -
             
     | 
| 
       267 
     | 
    
         
            -
                  def mutation(class_name: "user")
         
     | 
| 
       268 
     | 
    
         
            -
                    singularized_class_name = class_name.singularize
         
     | 
| 
       269 
     | 
    
         
            -
                    file_dir = "./app/graphql/mutations/base"
         
     | 
| 
       270 
     | 
    
         
            -
                    FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
         
     | 
| 
       271 
     | 
    
         
            -
                    file_path = "./app/graphql/mutations/base/#{singularized_class_name}/create_#{singularized_class_name}.rb"
         
     | 
| 
       272 
     | 
    
         
            -
                    return "Mutation already exist! #{file_path}" if File.exist?(file_path)
         
     | 
| 
       273 
     | 
    
         
            -
             
     | 
| 
       274 
     | 
    
         
            -
                    create_mutation_head(class_name: singularized_class_name)
         
     | 
| 
       275 
     | 
    
         
            -
                    relation_params = create_mutation_params(class_name: singularized_class_name)
         
     | 
| 
       276 
     | 
    
         
            -
                    create_mutation_after_params(class_name: singularized_class_name, relation_params: relation_params)
         
     | 
| 
       277 
     | 
    
         
            -
                    create_mutation_end(class_name: singularized_class_name)
         
     | 
| 
       278 
     | 
    
         
            -
                    update_mutation(class_name: singularized_class_name)
         
     | 
| 
       279 
     | 
    
         
            -
                    delete_mutation(class_name: singularized_class_name)
         
     | 
| 
       280 
     | 
    
         
            -
                    destroy_delete_mutation(class_name: singularized_class_name)
         
     | 
| 
       281 
     | 
    
         
            -
                    puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
         
     | 
| 
       282 
     | 
    
         
            -
                    file_path
         
     | 
| 
       283 
     | 
    
         
            -
                  rescue StandardError => e
         
     | 
| 
       284 
     | 
    
         
            -
                    raise(StandardError, e)
         
     | 
| 
      
 279 
     | 
    
         
            +
                      end
         
     | 
| 
      
 280 
     | 
    
         
            +
                    TEXT
         
     | 
| 
       285 
281 
     | 
    
         
             
                  end
         
     | 
| 
      
 282 
     | 
    
         
            +
                  file_path
         
     | 
| 
      
 283 
     | 
    
         
            +
                rescue StandardError => e
         
     | 
| 
      
 284 
     | 
    
         
            +
                  puts(e)
         
     | 
| 
       286 
285 
     | 
    
         
             
                end
         
     | 
| 
       287 
286 
     | 
    
         
             
              end
         
     | 
| 
       288 
287 
     | 
    
         
             
            end
         
     |