souls 0.18.2 → 0.20.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of souls might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/Gemfile.lock +1 -1
- data/README.md +7 -9
- data/Rakefile +9 -0
- data/exe/souls +30 -32
- data/lib/souls.rb +15 -37
- data/lib/souls/generate/application.rb +156 -0
- data/lib/souls/generate/model.rb +18 -0
- data/lib/souls/generate/mutation.rb +274 -0
- data/lib/souls/generate/policy.rb +50 -0
- data/lib/souls/generate/query.rb +56 -0
- data/lib/souls/generate/resolver.rb +153 -0
- data/lib/souls/generate/rspec_factory.rb +63 -0
- data/lib/souls/generate/rspec_model.rb +23 -0
- data/lib/souls/generate/rspec_mutation.rb +247 -0
- data/lib/souls/generate/rspec_policy.rb +50 -0
- data/lib/souls/generate/rspec_query.rb +169 -0
- data/lib/souls/generate/rspec_resolver.rb +189 -0
- data/lib/souls/generate/type.rb +83 -0
- data/lib/souls/init.rb +0 -1131
- data/lib/souls/version.rb +1 -1
- data/souls.gemspec +1 -1
- metadata +18 -6
- data/lib/souls/generate.rb +0 -520
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d78ed0a6ac81ec57cd9c7fe665a06cecace1b2340e99f7a7b431fae48c2fdda
|
4
|
+
data.tar.gz: 1235ad8b76775fc9243e00e695c94ec0e63ce6f43c6417be81b1969506d3aece
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8876fcdff3e8d94d0c081702f9561dd816b591d6eab718b37548d865ae44ee1e9354e7a062049fba1cdd97e48bc420c6f8e7ed74d62da2574d19b6b82d27dd2c
|
7
|
+
data.tar.gz: aa1e1855338316851ad4d7b79c2084f069df85e51a46ce662f0e900cb4098cf52174daaf96c9c740cefb9c4427cbba08cef70cf4758bca16891f72d7271a1956
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -28,11 +28,10 @@ You can focus on business logic. No more infra problems.
|
|
28
28
|
|
29
29
|
SOULs creates 5 types of framework.
|
30
30
|
|
31
|
-
1. API - GraphQL (Ruby) - Simple API
|
32
|
-
2.
|
33
|
-
3.
|
34
|
-
4.
|
35
|
-
5. Admin Web Client - Admin Console and CMS (TypeScript)
|
31
|
+
1. API - GraphQL (Ruby) - Simple API - Cloud Run
|
32
|
+
2. Worker - Google Pub/Sub Worker API (Ruby) - Cloud Run
|
33
|
+
3. Media Web Client - Media web client with SSG (TypeScript)
|
34
|
+
4. Admin Web Client - Admin Console and CMS (TypeScript)
|
36
35
|
|
37
36
|
## Dependency
|
38
37
|
|
@@ -71,10 +70,9 @@ And Create Your APP
|
|
71
70
|
### Choose SOULs Type:
|
72
71
|
|
73
72
|
1. API
|
74
|
-
2.
|
75
|
-
3.
|
76
|
-
4.
|
77
|
-
5. Admin Web
|
73
|
+
2. Workewr
|
74
|
+
3. Media Web
|
75
|
+
4. Admin Web
|
78
76
|
|
79
77
|
|
80
78
|
## SOULs Document
|
data/Rakefile
CHANGED
@@ -4,3 +4,12 @@ require "rspec/core/rake_task"
|
|
4
4
|
RSpec::Core::RakeTask.new(:spec)
|
5
5
|
|
6
6
|
task :default => :spec
|
7
|
+
|
8
|
+
namespace :task do
|
9
|
+
task :g do
|
10
|
+
file_path = "./lib/souls/generate/"
|
11
|
+
Souls::SOULS_METHODS.each do |f|
|
12
|
+
FileUtils.touch "#{file_path}#{f}.rb"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/exe/souls
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require "souls"
|
3
3
|
begin
|
4
|
-
require "./config/souls" unless ARGV[0] == "new" || ARGV[0] == "i"
|
4
|
+
require "./config/souls" unless ARGV[0] == "new" || ARGV[0] == "i" || ARGV[0] == "-v"
|
5
5
|
rescue
|
6
6
|
Souls::Init.config_init
|
7
7
|
end
|
@@ -63,51 +63,49 @@ begin
|
|
63
63
|
when "g", "generate"
|
64
64
|
case ARGV[1]
|
65
65
|
when "test_dir"
|
66
|
-
Souls::
|
67
|
-
when "policy"
|
68
|
-
Souls::Init.policy class_name: ARGV[2]
|
69
|
-
when "rspec_policy"
|
70
|
-
Souls::Init.rspec_policy class_name: ARGV[2]
|
71
|
-
when "node_type"
|
72
|
-
Souls::Init.node_type class_name: ARGV[2]
|
73
|
-
when "resolver"
|
74
|
-
Souls::Init.resolver class_name: ARGV[2]
|
75
|
-
when "job"
|
76
|
-
Souls::Init.job class_name: ARGV[2]
|
66
|
+
Souls::Generate.test_dir
|
77
67
|
when "model"
|
78
|
-
Souls::
|
68
|
+
Souls::Generate.model class_name: ARGV[2]
|
79
69
|
when "mutation"
|
80
|
-
Souls::
|
70
|
+
Souls::Generate.mutation class_name: ARGV[2]
|
81
71
|
when "query"
|
82
|
-
Souls::
|
72
|
+
Souls::Generate.query class_name: ARGV[2]
|
83
73
|
when "type"
|
84
|
-
Souls::
|
85
|
-
when "
|
86
|
-
Souls::
|
87
|
-
when "
|
88
|
-
Souls::
|
89
|
-
when "migration"
|
90
|
-
system "rake db:create_migration NAME=create_#{ARGV[2]}"
|
74
|
+
Souls::Generate.type class_name: ARGV[2]
|
75
|
+
when "resolver"
|
76
|
+
Souls::Generate.resolver class_name: ARGV[2]
|
77
|
+
when "policy"
|
78
|
+
Souls::Generate.policy class_name: ARGV[2]
|
91
79
|
when "rspec_factory"
|
92
|
-
Souls::
|
80
|
+
Souls::Generate.rspec_factory class_name: ARGV[2]
|
93
81
|
when "rspec_model"
|
94
|
-
Souls::
|
82
|
+
Souls::Generate.rspec_model class_name: ARGV[2]
|
95
83
|
when "rspec_mutation"
|
96
|
-
Souls::
|
84
|
+
Souls::Generate.rspec_mutation class_name: ARGV[2]
|
97
85
|
when "rspec_query"
|
98
|
-
Souls::
|
99
|
-
when "rspec_type"
|
100
|
-
Souls::Init.rspec_type class_name: ARGV[2]
|
86
|
+
Souls::Generate.rspec_query class_name: ARGV[2]
|
101
87
|
when "rspec_resolver"
|
102
|
-
Souls::
|
88
|
+
Souls::Generate.rspec_resolver class_name: ARGV[2]
|
89
|
+
when "rspec_policy"
|
90
|
+
Souls::Generate.rspec_policy class_name: ARGV[2]
|
91
|
+
when "node_type"
|
92
|
+
Souls::Generate.node_type class_name: ARGV[2]
|
93
|
+
when "job"
|
94
|
+
Souls::Generate.job class_name: ARGV[2]
|
95
|
+
when "migrate"
|
96
|
+
Souls::Generate.single_migrate class_name: ARGV[2]
|
97
|
+
when "migrate_all"
|
98
|
+
Souls::Generate.migrate_all
|
99
|
+
when "migration"
|
100
|
+
system "rake db:create_migration NAME=create_#{ARGV[2]}"
|
103
101
|
else
|
104
102
|
"SOULs!"
|
105
103
|
end
|
106
104
|
when "d"
|
107
|
-
Souls::
|
105
|
+
Souls::Generate.delete_all class_name: ARGV[1]
|
108
106
|
when "update"
|
109
|
-
Souls::
|
110
|
-
Souls::
|
107
|
+
Souls::Generate.add_delete class_name: ARGV[1]
|
108
|
+
Souls::Generate.single_migrate class_name: ARGV[1]
|
111
109
|
when "db:create"
|
112
110
|
system "rake db:create && rake db:create RACK_ENV=test"
|
113
111
|
when "db:migrate"
|
data/lib/souls.rb
CHANGED
@@ -1,11 +1,25 @@
|
|
1
1
|
require "souls/version"
|
2
2
|
require "active_support/core_ext/string/inflections"
|
3
3
|
require "souls/init"
|
4
|
-
require "souls/generate"
|
5
4
|
require "json"
|
6
5
|
require "fileutils"
|
6
|
+
Dir["./lib/souls/generate/*.rb"].each { |f| require f }
|
7
7
|
|
8
8
|
module Souls
|
9
|
+
SOULS_METHODS = [
|
10
|
+
"model",
|
11
|
+
"query",
|
12
|
+
"mutation",
|
13
|
+
"type",
|
14
|
+
"resolver",
|
15
|
+
"policy",
|
16
|
+
"rspec_factory",
|
17
|
+
"rspec_model",
|
18
|
+
"rspec_query",
|
19
|
+
"rspec_mutation",
|
20
|
+
"rspec_resolver",
|
21
|
+
"rspec_policy"
|
22
|
+
]
|
9
23
|
class Error < StandardError; end
|
10
24
|
class << self
|
11
25
|
attr_accessor :configuration
|
@@ -25,42 +39,6 @@ module Souls
|
|
25
39
|
app = Souls.configuration.app
|
26
40
|
system "gcloud scheduler jobs create http #{app}-awake --schedule '0,10,20,30,40,50 * * * *' --uri #{url} --http-method GET"
|
27
41
|
end
|
28
|
-
|
29
|
-
def deploy_local
|
30
|
-
`docker network create --driver bridge shared`
|
31
|
-
|
32
|
-
`docker run -d --name proxy \
|
33
|
-
-p 80:80 -p 443:443 \
|
34
|
-
-v "/var/run/docker.sock:/tmp/docker.sock:ro" \
|
35
|
-
-v "$pwd/certs:/etc/nginx/certs:ro" \
|
36
|
-
-v "/etc/nginx/vhost.d" \
|
37
|
-
-v "/usr/share/nginx/html" \
|
38
|
-
--network shared \
|
39
|
-
--restart always \
|
40
|
-
jwilder/nginx-proxy`
|
41
|
-
|
42
|
-
`docker run -d --name letsencrypt \
|
43
|
-
-v "/home/certs:/etc/nginx/certs" \
|
44
|
-
-v "/var/run/docker.sock:/var/run/docker.sock:ro" \
|
45
|
-
--volumes-from proxy \
|
46
|
-
--network shared \
|
47
|
-
--restart always \
|
48
|
-
jrcs/letsencrypt-nginx-proxy-companion`
|
49
|
-
|
50
|
-
`docker run -d --name nginx \
|
51
|
-
-p 80:80 \
|
52
|
-
-e VIRTUAL_HOST=souls.el-soul.com \
|
53
|
-
-e LETSENCRYPT_HOST=souls.el-soul.com \
|
54
|
-
-e LETSENCRYPT_EMAIL=info@gmail.com \
|
55
|
-
--network shared \
|
56
|
-
--link web \
|
57
|
-
poppinfumi/ruby-nginx:latest`
|
58
|
-
|
59
|
-
`docker run -d --name web \
|
60
|
-
-p 3000:3000 \
|
61
|
-
--network shared \
|
62
|
-
poppinfumi/souls_api`
|
63
|
-
end
|
64
42
|
end
|
65
43
|
|
66
44
|
def self.configure
|
@@ -0,0 +1,156 @@
|
|
1
|
+
module Souls
|
2
|
+
module Generate
|
3
|
+
class << self
|
4
|
+
## Common Methods
|
5
|
+
def generated_paths class_name: "user"
|
6
|
+
singularized_class_name = class_name.singularize.underscore
|
7
|
+
pluralized_class_name = class_name.pluralize.underscore
|
8
|
+
[
|
9
|
+
"./app/models/#{singularized_class_name}.rb",
|
10
|
+
"./app/policies/#{singularized_class_name}_policy.rb",
|
11
|
+
"./app/graphql/mutations/create_#{singularized_class_name}.rb",
|
12
|
+
"./app/graphql/mutations/delete_#{singularized_class_name}.rb",
|
13
|
+
"./app/graphql/mutations/destroy_delete_#{singularized_class_name}.rb",
|
14
|
+
"./app/graphql/mutations/update_#{singularized_class_name}.rb",
|
15
|
+
"./app/graphql/queries/#{singularized_class_name}.rb",
|
16
|
+
"./app/graphql/queries/#{pluralized_class_name}.rb",
|
17
|
+
"./app/graphql/resolvers/#{singularized_class_name}_search.rb",
|
18
|
+
"./app/graphql/types/#{singularized_class_name}_type.rb",
|
19
|
+
"./app/graphql/types/#{singularized_class_name}_node_type.rb",
|
20
|
+
"./spec/factories/#{pluralized_class_name}.rb",
|
21
|
+
"./spec/mutations/#{singularized_class_name}_spec.rb",
|
22
|
+
"./spec/models/#{singularized_class_name}_spec.rb",
|
23
|
+
"./spec/queries/#{singularized_class_name}_spec.rb",
|
24
|
+
"./spec/policies/#{singularized_class_name}_policy_spec.rb",
|
25
|
+
"./spec/resolvers/#{singularized_class_name}_search_spec.rb"
|
26
|
+
]
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_type_and_name line
|
30
|
+
line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_tables
|
34
|
+
path = "./db/schema.rb"
|
35
|
+
tables = []
|
36
|
+
File.open(path, "r") do |f|
|
37
|
+
f.each_line.with_index do |line, i|
|
38
|
+
tables << line.split("\"")[1] if line.include?("create_table")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
tables
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_dir
|
45
|
+
FileUtils.mkdir_p "./app/graphql/mutations"
|
46
|
+
FileUtils.mkdir_p "./app/graphql/queries"
|
47
|
+
FileUtils.mkdir_p "./app/graphql/types"
|
48
|
+
FileUtils.mkdir_p "./app/graphql/resolvers"
|
49
|
+
FileUtils.mkdir_p "./app/models"
|
50
|
+
FileUtils.mkdir_p "./app/policies"
|
51
|
+
FileUtils.mkdir_p "./spec/factories"
|
52
|
+
FileUtils.mkdir_p "./spec/queries"
|
53
|
+
FileUtils.mkdir_p "./spec/mutations"
|
54
|
+
FileUtils.mkdir_p "./spec/models"
|
55
|
+
FileUtils.mkdir_p "./spec/resolvers"
|
56
|
+
FileUtils.mkdir_p "./spec/policies"
|
57
|
+
FileUtils.mkdir_p "./config"
|
58
|
+
FileUtils.touch "./config/souls.rb"
|
59
|
+
FileUtils.mkdir_p "./db/"
|
60
|
+
FileUtils.touch "./db/schema.rb"
|
61
|
+
puts "test dir created!"
|
62
|
+
end
|
63
|
+
|
64
|
+
def type_check type
|
65
|
+
{
|
66
|
+
bigint: "Integer",
|
67
|
+
string: "String",
|
68
|
+
float: "Float",
|
69
|
+
text: "String",
|
70
|
+
datetime: "GraphQL::Types::ISO8601DateTime",
|
71
|
+
date: "GraphQL::Types::ISO8601DateTime",
|
72
|
+
boolean: "Boolean",
|
73
|
+
integer: "Integer"
|
74
|
+
}[type.to_sym]
|
75
|
+
end
|
76
|
+
|
77
|
+
def get_test_type type
|
78
|
+
{
|
79
|
+
bigint: 1,
|
80
|
+
float: 4.2,
|
81
|
+
string: '"MyString"',
|
82
|
+
text: '"MyString"',
|
83
|
+
datetime: "Time.now",
|
84
|
+
date: "Time.now",
|
85
|
+
boolean: false,
|
86
|
+
integer: 1
|
87
|
+
}[type.to_sym]
|
88
|
+
end
|
89
|
+
|
90
|
+
def table_check line: "", class_name: ""
|
91
|
+
if line.include?("create_table") && (line.split(" ")[1].gsub("\"", "").gsub(",", "") == class_name.pluralize.to_s)
|
92
|
+
return true
|
93
|
+
end
|
94
|
+
false
|
95
|
+
end
|
96
|
+
|
97
|
+
def migrate class_name: "souls"
|
98
|
+
singularized_class_name = class_name.singularize
|
99
|
+
[
|
100
|
+
model: model(class_name: singularized_class_name),
|
101
|
+
types: type(class_name: singularized_class_name),
|
102
|
+
resolver: resolver(class_name: singularized_class_name),
|
103
|
+
rspec_factory: rspec_factory(class_name: singularized_class_name),
|
104
|
+
rspec_model: rspec_model(class_name: singularized_class_name),
|
105
|
+
rspec_mutation: rspec_mutation(class_name: singularized_class_name),
|
106
|
+
rspec_query: rspec_query(class_name: singularized_class_name),
|
107
|
+
rspec_resolver: rspec_resolver(class_name: singularized_class_name),
|
108
|
+
queries: query(class_name: singularized_class_name),
|
109
|
+
mutations: mutation(class_name: singularized_class_name)
|
110
|
+
]
|
111
|
+
end
|
112
|
+
|
113
|
+
def delete_all class_name: "souls"
|
114
|
+
singularized_class_name = class_name.singularize.underscore
|
115
|
+
pluralized_class_name = class_name.pluralize.underscore
|
116
|
+
FileUtils.rm "./app/models/#{singularized_class_name}.rb"
|
117
|
+
FileUtils.rm "./app/policies/#{singularized_class_name}_policy.rb"
|
118
|
+
FileUtils.rm_rf "./app/graphql/mutations/#{singularized_class_name}"
|
119
|
+
FileUtils.rm "./app/graphql/queries/#{singularized_class_name}.rb"
|
120
|
+
FileUtils.rm "./app/graphql/queries/#{pluralized_class_name}.rb"
|
121
|
+
FileUtils.rm "./app/graphql/resolvers/#{singularized_class_name}_search.rb"
|
122
|
+
FileUtils.rm "./app/graphql/types/#{singularized_class_name}_type.rb"
|
123
|
+
FileUtils.rm "./app/graphql/types/#{singularized_class_name}_node_type.rb"
|
124
|
+
FileUtils.rm "./spec/factories/#{pluralized_class_name}.rb"
|
125
|
+
FileUtils.rm "./spec/mutations/#{singularized_class_name}_spec.rb"
|
126
|
+
FileUtils.rm "./spec/models/#{singularized_class_name}_spec.rb"
|
127
|
+
FileUtils.rm "./spec/queries/#{singularized_class_name}_spec.rb"
|
128
|
+
FileUtils.rm "./spec/policies/#{singularized_class_name}_policy_spec.rb"
|
129
|
+
FileUtils.rm "./spec/resolvers/#{singularized_class_name}_search_spec.rb"
|
130
|
+
puts "deleted #{class_name.camelize} CRUD!"
|
131
|
+
rescue StandardError => error
|
132
|
+
puts error
|
133
|
+
end
|
134
|
+
|
135
|
+
def single_migrate class_name: "user"
|
136
|
+
puts "◆◆◆ Let's Auto Generate CRUD API SET ◆◆◆\n"
|
137
|
+
migrate class_name: class_name
|
138
|
+
puts "Generated #{class_name.camelize} CRUD Files\n"
|
139
|
+
Souls::Generate.generated_paths(class_name: class_name).each { |f| puts f }
|
140
|
+
puts "\nAll files created from ./db/schema.rb"
|
141
|
+
puts "\n\n"
|
142
|
+
end
|
143
|
+
|
144
|
+
def migrate_all
|
145
|
+
puts "◆◆◆ Let's Auto Generate CRUD API SET ◆◆◆\n"
|
146
|
+
get_tables.each do |class_name|
|
147
|
+
migrate class_name: class_name.singularize
|
148
|
+
puts "Generated #{class_name.camelize} CRUD Files\n"
|
149
|
+
Souls::Generate.generated_paths(class_name: class_name).each { |f| puts f }
|
150
|
+
puts "\n"
|
151
|
+
end
|
152
|
+
puts "\nAll files created from ./db/schema.rb"
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Souls
|
2
|
+
module Generate
|
3
|
+
class << self
|
4
|
+
## Generate Model
|
5
|
+
def model class_name: "souls"
|
6
|
+
file_path = "./app/models/#{class_name.singularize}.rb"
|
7
|
+
return "Model already exist! #{file_path}" if File.exist? file_path
|
8
|
+
File.open(file_path, "w") do |f|
|
9
|
+
f.write <<~EOS
|
10
|
+
class #{class_name.camelize} < ActiveRecord::Base
|
11
|
+
end
|
12
|
+
EOS
|
13
|
+
end
|
14
|
+
file_path
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,274 @@
|
|
1
|
+
module Souls
|
2
|
+
module Generate
|
3
|
+
class << self
|
4
|
+
## Generate 4 Mutations - ["create", "update", "delete", "destroy_delete"]
|
5
|
+
## 1.Mutation - Create
|
6
|
+
def create_mutation_head class_name: "souls"
|
7
|
+
dir_name = "./app/graphql/mutations/#{class_name}"
|
8
|
+
FileUtils.mkdir_p dir_name unless Dir.exist? dir_name
|
9
|
+
file_path = "./app/graphql/mutations/#{class_name}/create_#{class_name}.rb"
|
10
|
+
File.open(file_path, "w") do |new_line|
|
11
|
+
new_line.write <<~EOS
|
12
|
+
module Mutations
|
13
|
+
module #{class_name.camelize}
|
14
|
+
class Create#{class_name.camelize} < BaseMutation
|
15
|
+
field :#{class_name}_edge, Types::#{class_name.camelize}NodeType, null: false
|
16
|
+
field :error, String, null: true
|
17
|
+
|
18
|
+
EOS
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_mutation_params class_name: "souls"
|
23
|
+
file_path = "./app/graphql/mutations/#{class_name}/create_#{class_name}.rb"
|
24
|
+
path = "./db/schema.rb"
|
25
|
+
@on = false
|
26
|
+
@user_exist = false
|
27
|
+
@relation_params = []
|
28
|
+
File.open(file_path, "a") do |new_line|
|
29
|
+
File.open(path, "r") do |f|
|
30
|
+
f.each_line.with_index do |line, i|
|
31
|
+
if @on
|
32
|
+
if line.include?("end") || line.include?("t.index")
|
33
|
+
if @user_exist
|
34
|
+
new_line.write <<-EOS
|
35
|
+
|
36
|
+
def resolve **args
|
37
|
+
args[:user_id] = context[:user].id
|
38
|
+
EOS
|
39
|
+
else
|
40
|
+
new_line.write <<-EOS
|
41
|
+
|
42
|
+
def resolve **args
|
43
|
+
EOS
|
44
|
+
end
|
45
|
+
break
|
46
|
+
end
|
47
|
+
field = "[String]" if line.include?("array: true")
|
48
|
+
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
49
|
+
field ||= type_check type
|
50
|
+
case name
|
51
|
+
when "user_id"
|
52
|
+
@user_exist = true
|
53
|
+
when /$*_id\z/
|
54
|
+
@relation_params << name
|
55
|
+
new_line.write " argument :#{name}, String, required: false\n"
|
56
|
+
when "created_at", "updated_at"
|
57
|
+
next
|
58
|
+
else
|
59
|
+
new_line.write " argument :#{name}, #{field}, required: false\n"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
@on = true if table_check(line: line, class_name: class_name)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
@relation_params
|
67
|
+
end
|
68
|
+
|
69
|
+
def create_mutation_after_params class_name: "article", relation_params: []
|
70
|
+
return false if relation_params.empty?
|
71
|
+
file_path = "./app/graphql/mutations/#{class_name}/create_#{class_name}.rb"
|
72
|
+
relation_params.each do |params_name|
|
73
|
+
File.open(file_path, "a") do |new_line|
|
74
|
+
new_line.write " _, args[:#{params_name}] = SoulsApiSchema.from_global_id(args[:#{params_name}])\n"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
true
|
78
|
+
end
|
79
|
+
|
80
|
+
def create_mutation_end class_name: "souls"
|
81
|
+
file_path = "./app/graphql/mutations/#{class_name}/create_#{class_name}.rb"
|
82
|
+
File.open(file_path, "a") do |new_line|
|
83
|
+
new_line.write <<~EOS
|
84
|
+
#{class_name} = ::#{class_name.camelize}.new args
|
85
|
+
if #{class_name}.save
|
86
|
+
{ #{class_name}_edge: { node: #{class_name} } }
|
87
|
+
else
|
88
|
+
{ error: #{class_name}.errors.full_messages }
|
89
|
+
end
|
90
|
+
rescue StandardError => error
|
91
|
+
GraphQL::ExecutionError.new error
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
EOS
|
97
|
+
end
|
98
|
+
file_path
|
99
|
+
end
|
100
|
+
|
101
|
+
## 2.Mutation - Update
|
102
|
+
def update_mutation_head class_name: "souls"
|
103
|
+
file_path = "./app/graphql/mutations/#{class_name}/update_#{class_name}.rb"
|
104
|
+
File.open(file_path, "w") do |new_line|
|
105
|
+
new_line.write <<~EOS
|
106
|
+
module Mutations
|
107
|
+
module #{class_name.camelize}
|
108
|
+
class Update#{class_name.camelize} < BaseMutation
|
109
|
+
field :#{class_name}_edge, Types::#{class_name.camelize}NodeType, null: false
|
110
|
+
|
111
|
+
argument :id, String, required: true
|
112
|
+
EOS
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def update_mutation_params class_name: "souls"
|
117
|
+
file_path = "./app/graphql/mutations/#{class_name}/update_#{class_name}.rb"
|
118
|
+
path = "./db/schema.rb"
|
119
|
+
@on = false
|
120
|
+
@user_exist = false
|
121
|
+
@relation_params = []
|
122
|
+
File.open(file_path, "a") do |new_line|
|
123
|
+
File.open(path, "r") do |f|
|
124
|
+
f.each_line.with_index do |line, i|
|
125
|
+
if @on
|
126
|
+
if line.include?("end") || line.include?("t.index")
|
127
|
+
if @user_exist
|
128
|
+
new_line.write <<-EOS
|
129
|
+
|
130
|
+
def resolve **args
|
131
|
+
args[:user_id] = context[:user].id
|
132
|
+
_, args[:id] = SoulsApiSchema.from_global_id(args[:id])
|
133
|
+
EOS
|
134
|
+
else
|
135
|
+
new_line.write <<-EOS
|
136
|
+
|
137
|
+
def resolve **args
|
138
|
+
_, args[:id] = SoulsApiSchema.from_global_id(args[:id])
|
139
|
+
EOS
|
140
|
+
end
|
141
|
+
break
|
142
|
+
end
|
143
|
+
field = "[String]" if line.include?("array: true")
|
144
|
+
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
145
|
+
field ||= type_check type
|
146
|
+
case name
|
147
|
+
when "user_id"
|
148
|
+
@user_exist = true
|
149
|
+
when /$*_id\z/
|
150
|
+
@relation_params << name
|
151
|
+
new_line.write " argument :#{name}, String, required: false\n"
|
152
|
+
when "created_at", "updated_at"
|
153
|
+
next
|
154
|
+
else
|
155
|
+
new_line.write " argument :#{name}, #{field}, required: false\n"
|
156
|
+
end
|
157
|
+
end
|
158
|
+
@on = true if table_check(line: line, class_name: class_name)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
@relation_params
|
163
|
+
end
|
164
|
+
|
165
|
+
def update_mutation_after_params class_name: "article", relation_params: []
|
166
|
+
return false if relation_params.empty?
|
167
|
+
file_path = "./app/graphql/mutations/#{class_name}/update_#{class_name}.rb"
|
168
|
+
relation_params.each do |params_name|
|
169
|
+
File.open(file_path, "a") do |new_line|
|
170
|
+
new_line.write " _, args[:#{params_name}] = SoulsApiSchema.from_global_id(args[:#{params_name}])\n"
|
171
|
+
end
|
172
|
+
end
|
173
|
+
true
|
174
|
+
end
|
175
|
+
|
176
|
+
def update_mutation_end class_name: "souls"
|
177
|
+
file_path = "./app/graphql/mutations/#{class_name}/update_#{class_name}.rb"
|
178
|
+
File.open(file_path, "a") do |new_line|
|
179
|
+
new_line.write <<~EOS
|
180
|
+
#{class_name} = ::#{class_name.camelize}.find args[:id]
|
181
|
+
#{class_name}.update args
|
182
|
+
{ #{class_name}_edge: { node: ::#{class_name.camelize}.find(args[:id]) } }
|
183
|
+
rescue StandardError => error
|
184
|
+
GraphQL::ExecutionError.new error
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
EOS
|
190
|
+
end
|
191
|
+
file_path
|
192
|
+
end
|
193
|
+
|
194
|
+
def update_mutation class_name: "souls"
|
195
|
+
update_mutation_head class_name: class_name
|
196
|
+
relation_params = update_mutation_params class_name: class_name
|
197
|
+
update_mutation_after_params class_name: class_name, relation_params: relation_params
|
198
|
+
update_mutation_end class_name: class_name
|
199
|
+
end
|
200
|
+
|
201
|
+
# 3. Mutation - Delete
|
202
|
+
def delete_mutation class_name: "souls"
|
203
|
+
file_path = "./app/graphql/mutations/#{class_name}/delete_#{class_name}.rb"
|
204
|
+
File.open(file_path, "w") do |f|
|
205
|
+
f.write <<~EOS
|
206
|
+
module Mutations
|
207
|
+
module #{class_name.camelize}
|
208
|
+
class Delete#{class_name.camelize} < BaseMutation
|
209
|
+
field :#{class_name}, Types::#{class_name.camelize}Type, null: false
|
210
|
+
argument :id, String, required: true
|
211
|
+
|
212
|
+
def resolve **args
|
213
|
+
_, data_id = SoulsApiSchema.from_global_id args[:id]
|
214
|
+
#{class_name} = ::#{class_name.camelize}.find data_id
|
215
|
+
#{class_name}.update(is_deleted: true)
|
216
|
+
{ #{class_name}: ::#{class_name.camelize}.find(data_id) }
|
217
|
+
rescue StandardError => error
|
218
|
+
GraphQL::ExecutionError.new error
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
EOS
|
224
|
+
end
|
225
|
+
file_path
|
226
|
+
end
|
227
|
+
|
228
|
+
# 4. Mutation - Destroy Delete
|
229
|
+
def destroy_delete_mutation class_name: "souls"
|
230
|
+
file_path = "./app/graphql/mutations/#{class_name}/destroy_delete_#{class_name}.rb"
|
231
|
+
File.open(file_path, "w") do |f|
|
232
|
+
f.write <<~EOS
|
233
|
+
module Mutations
|
234
|
+
module #{class_name.camelize}
|
235
|
+
class DestroyDelete#{class_name.camelize} < BaseMutation
|
236
|
+
field :#{class_name}, Types::#{class_name.camelize}Type, null: false
|
237
|
+
argument :id, String, required: true
|
238
|
+
|
239
|
+
def resolve **args
|
240
|
+
_, data_id = SoulsApiSchema.from_global_id args[:id]
|
241
|
+
#{class_name} = ::#{class_name.camelize}.find data_id
|
242
|
+
#{class_name}.destroy
|
243
|
+
{ #{class_name}: #{class_name} }
|
244
|
+
rescue StandardError => error
|
245
|
+
GraphQL::ExecutionError.new error
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
250
|
+
EOS
|
251
|
+
end
|
252
|
+
file_path
|
253
|
+
rescue StandardError => error
|
254
|
+
puts error
|
255
|
+
end
|
256
|
+
|
257
|
+
def mutation class_name: "souls"
|
258
|
+
singularized_class_name = class_name.singularize
|
259
|
+
|
260
|
+
create_mutation_head class_name: singularized_class_name
|
261
|
+
relation_params = create_mutation_params class_name: singularized_class_name
|
262
|
+
create_mutation_after_params class_name: singularized_class_name, relation_params: relation_params
|
263
|
+
[
|
264
|
+
create_mutation_end(class_name: singularized_class_name),
|
265
|
+
update_mutation(class_name: singularized_class_name),
|
266
|
+
delete_mutation(class_name: singularized_class_name),
|
267
|
+
destroy_delete_mutation(class_name: singularized_class_name)
|
268
|
+
]
|
269
|
+
rescue StandardError => error
|
270
|
+
puts error
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|
274
|
+
end
|