souls 0.44.6 → 0.45.3
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 +5 -2
- data/exe/souls +9 -1
- data/lib/souls/api/generate/application.rb +145 -143
- data/lib/souls/api/generate/connection.rb +1 -1
- data/lib/souls/api/generate/edge.rb +1 -1
- data/lib/souls/api/generate/model.rb +1 -1
- data/lib/souls/api/generate/mutation.rb +221 -219
- data/lib/souls/api/generate/policy.rb +1 -1
- data/lib/souls/api/generate/query.rb +49 -47
- data/lib/souls/api/generate/resolver.rb +123 -121
- data/lib/souls/api/generate/rspec_factory.rb +49 -47
- data/lib/souls/api/generate/rspec_model.rb +1 -1
- data/lib/souls/api/generate/rspec_mutation.rb +215 -213
- data/lib/souls/api/generate/rspec_policy.rb +1 -1
- data/lib/souls/api/generate/rspec_query.rb +134 -132
- data/lib/souls/api/generate/rspec_resolver.rb +159 -157
- data/lib/souls/api/generate/type.rb +4 -4
- data/lib/souls/cli/create/index.rb +1 -1
- 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/mailer.rb +1 -0
- data/lib/souls/worker/generate/mutation.rb +11 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e5e5a1971f6e91bb05bd14759a92ac4740149f501c3b81da75a8fb976cdd90a
|
4
|
+
data.tar.gz: 8674af630e07961ca7908dfd50b362577ccc5ac663e1b56a1ce4fe35a34ae01b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9d4a2dc723c00bff7213a05f5943b0624d2580703a9e6b38143aa9ea55b4bbf39f1a0b3cca984887c257f66440d7eb0ca73bd977b926e0b83ddcc5a631f2f8f
|
7
|
+
data.tar.gz: bf101e8b42a4a60428b2b975a9220f740df2d65bf6cdd73cc5f7cdb5b4babbce8810def35fff330de7f3f4b2ed3c5e299dac08228047e7bfee8602be4b3c9f5a
|
data/README.md
CHANGED
@@ -33,11 +33,10 @@ SOULs バックエンドには `API` と `Worker` の 2 つのタイプがあり
|
|
33
33
|
|
34
34
|
SOULs フレームワークでは [Monorepo](https://en.wikipedia.org/wiki/Monorepo) によって一つのパッケージでアプリケーションを管理します。
|
35
35
|
|
36
|
-
SOULs creates
|
36
|
+
SOULs creates 2 types of framework.
|
37
37
|
|
38
38
|
1. API - GraphQL (Ruby) - Simple API - Cloud Run
|
39
39
|
2. Worker - Google Pub/Sub Messaging Worker API (Ruby) - Cloud Run
|
40
|
-
3. Frontend - React Application (TypeScript) - Firebase
|
41
40
|
|
42
41
|
## Dependency
|
43
42
|
|
@@ -56,6 +55,8 @@ SOULs creates 3 types of framework.
|
|
56
55
|
- [Google Cloud Container Registry](https://cloud.google.com/container-registry)
|
57
56
|
- [Google Firebase](https://firebase.google.com/)
|
58
57
|
- [Google Cloud Scheduler](https://cloud.google.com/scheduler)
|
58
|
+
- [Google Cloud VPC](https://cloud.google.com/vpc)
|
59
|
+
- [Google Cloud Nat](https://cloud.google.com/nat)
|
59
60
|
- [Github Actions](https://github.com/features/actions)
|
60
61
|
|
61
62
|
## Installation
|
@@ -101,8 +102,10 @@ souls upgrade gemfile
|
|
101
102
|
Souls.configure do |config|
|
102
103
|
config.app = "souls-api"
|
103
104
|
config.project_id = "souls-api"
|
105
|
+
config.endpoint = "/endpoint"
|
104
106
|
config.strain = "api"
|
105
107
|
config.fixed_gems = ["selenium-webdriver", "pg"]
|
108
|
+
config.workers = []
|
106
109
|
end
|
107
110
|
```
|
108
111
|
|
data/exe/souls
CHANGED
@@ -65,7 +65,15 @@ begin
|
|
65
65
|
when "bashrc", "zshrc"
|
66
66
|
Souls::Init.generate_cd
|
67
67
|
when "s", "server"
|
68
|
-
|
68
|
+
all = ARGV[1]
|
69
|
+
case all
|
70
|
+
when "all"
|
71
|
+
Dir.chdir(Souls.get_mother_path.to_s) do
|
72
|
+
system("foreman start -f Procfile.dev")
|
73
|
+
end
|
74
|
+
else
|
75
|
+
system("foreman start -f Procfile.dev")
|
76
|
+
end
|
69
77
|
when "c", "console"
|
70
78
|
strain = Souls.configuration.strain
|
71
79
|
case strain
|
@@ -1,164 +1,166 @@
|
|
1
1
|
module Souls
|
2
2
|
module Api::Generate
|
3
3
|
## Common Methods
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
4
|
+
class << self
|
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/edges/#{singularized_class_name}_edge.rb",
|
20
|
+
"./app/graphql/types/connections/#{singularized_class_name}_connection.rb",
|
21
|
+
"./spec/factories/#{pluralized_class_name}.rb",
|
22
|
+
"./spec/mutations/#{singularized_class_name}_spec.rb",
|
23
|
+
"./spec/models/#{singularized_class_name}_spec.rb",
|
24
|
+
"./spec/queries/#{singularized_class_name}_spec.rb",
|
25
|
+
"./spec/policies/#{singularized_class_name}_policy_spec.rb",
|
26
|
+
"./spec/resolvers/#{singularized_class_name}_search_spec.rb"
|
27
|
+
]
|
28
|
+
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
def get_type_and_name(line)
|
31
|
+
line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
32
|
+
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
def get_tables
|
35
|
+
path = "./db/schema.rb"
|
36
|
+
tables = []
|
37
|
+
File.open(path, "r") do |f|
|
38
|
+
f.each_line.with_index do |line, _i|
|
39
|
+
tables << line.split("\"")[1] if line.include?("create_table")
|
40
|
+
end
|
39
41
|
end
|
42
|
+
tables
|
40
43
|
end
|
41
|
-
tables
|
42
|
-
end
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
45
|
+
def test_dir
|
46
|
+
FileUtils.mkdir_p("./app/graphql/mutations")
|
47
|
+
FileUtils.mkdir_p("./app/graphql/queries")
|
48
|
+
FileUtils.mkdir_p("./app/graphql/types")
|
49
|
+
FileUtils.mkdir_p("./app/graphql/resolvers")
|
50
|
+
FileUtils.mkdir_p("./app/models")
|
51
|
+
FileUtils.mkdir_p("./app/policies")
|
52
|
+
FileUtils.mkdir_p("./spec/factories")
|
53
|
+
FileUtils.mkdir_p("./spec/queries")
|
54
|
+
FileUtils.mkdir_p("./spec/mutations")
|
55
|
+
FileUtils.mkdir_p("./spec/models")
|
56
|
+
FileUtils.mkdir_p("./spec/resolvers")
|
57
|
+
FileUtils.mkdir_p("./spec/policies")
|
58
|
+
FileUtils.mkdir_p("./config")
|
59
|
+
FileUtils.touch("./config/souls.rb")
|
60
|
+
FileUtils.mkdir_p("./db/")
|
61
|
+
FileUtils.touch("./db/schema.rb")
|
62
|
+
puts("test dir created!")
|
63
|
+
end
|
63
64
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
65
|
+
def type_check(type)
|
66
|
+
{
|
67
|
+
bigint: "Integer",
|
68
|
+
string: "String",
|
69
|
+
float: "Float",
|
70
|
+
text: "String",
|
71
|
+
datetime: "String",
|
72
|
+
date: "String",
|
73
|
+
boolean: "Boolean",
|
74
|
+
integer: "Integer"
|
75
|
+
}[type.to_sym]
|
76
|
+
end
|
76
77
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
78
|
+
def get_type(type)
|
79
|
+
{
|
80
|
+
bigint: "Integer",
|
81
|
+
string: "String",
|
82
|
+
float: "Float",
|
83
|
+
text: "String",
|
84
|
+
datetime: "GraphQL::Types::ISO8601DateTime",
|
85
|
+
date: "GraphQL::Types::ISO8601DateTime",
|
86
|
+
boolean: "Boolean",
|
87
|
+
integer: "Integer"
|
88
|
+
}[type.to_sym]
|
89
|
+
end
|
89
90
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
91
|
+
def get_test_type(type)
|
92
|
+
{
|
93
|
+
bigint: "rand(1..10)",
|
94
|
+
float: 4.2,
|
95
|
+
string: '"MyString"',
|
96
|
+
text: '"MyString"',
|
97
|
+
datetime: "Time.now",
|
98
|
+
date: "Time.now.strftime('%F')",
|
99
|
+
boolean: false,
|
100
|
+
integer: "rand(1..10)"
|
101
|
+
}[type.to_sym]
|
102
|
+
end
|
102
103
|
|
103
|
-
|
104
|
-
|
104
|
+
def table_check(line: "", class_name: "")
|
105
|
+
if line.include?("create_table") && (line.split[1].gsub("\"", "").gsub(",", "") == class_name.pluralize.to_s)
|
105
106
|
|
106
|
-
|
107
|
-
|
107
|
+
return true
|
108
|
+
end
|
108
109
|
|
109
|
-
|
110
|
-
|
110
|
+
false
|
111
|
+
end
|
111
112
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
113
|
+
def scaffold(class_name: "user")
|
114
|
+
singularized_class_name = class_name.singularize
|
115
|
+
model(class_name: singularized_class_name)
|
116
|
+
type(class_name: singularized_class_name)
|
117
|
+
edge(class_name: singularized_class_name)
|
118
|
+
connection(class_name: singularized_class_name)
|
119
|
+
resolver(class_name: singularized_class_name)
|
120
|
+
rspec_factory(class_name: singularized_class_name)
|
121
|
+
rspec_model(class_name: singularized_class_name)
|
122
|
+
rspec_mutation(class_name: singularized_class_name)
|
123
|
+
rspec_query(class_name: singularized_class_name)
|
124
|
+
rspec_resolver(class_name: singularized_class_name)
|
125
|
+
query(class_name: singularized_class_name)
|
126
|
+
mutation(class_name: singularized_class_name)
|
127
|
+
policy(class_name: singularized_class_name)
|
128
|
+
rspec_policy(class_name: singularized_class_name)
|
129
|
+
rescue StandardError => e
|
130
|
+
puts(e.backtrace)
|
131
|
+
raise(StandardError, e)
|
132
|
+
end
|
132
133
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
134
|
+
def scaffold_all
|
135
|
+
puts(Paint["Let's Go SOULs AUTO CRUD Assist!\n", :cyan])
|
136
|
+
Souls::Api::Generate.get_tables.each do |table|
|
137
|
+
Souls::Api::Generate.scaffold(class_name: table.singularize)
|
138
|
+
puts(Paint["Generated #{table.camelize} CRUD Files\n", :yellow])
|
139
|
+
end
|
138
140
|
end
|
139
|
-
end
|
140
141
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
142
|
+
def delete_all(class_name: "user")
|
143
|
+
singularized_class_name = class_name.singularize.underscore
|
144
|
+
pluralized_class_name = class_name.pluralize.underscore
|
145
|
+
FileUtils.rm("./app/models/#{singularized_class_name}.rb")
|
146
|
+
FileUtils.rm("./app/policies/#{singularized_class_name}_policy.rb")
|
147
|
+
FileUtils.rm_rf("./app/graphql/mutations/base/#{singularized_class_name}")
|
148
|
+
FileUtils.rm("./app/graphql/queries/#{singularized_class_name}.rb")
|
149
|
+
FileUtils.rm("./app/graphql/queries/#{pluralized_class_name}.rb")
|
150
|
+
FileUtils.rm("./app/graphql/resolvers/#{singularized_class_name}_search.rb")
|
151
|
+
FileUtils.rm("./app/graphql/types/#{singularized_class_name}_type.rb")
|
152
|
+
FileUtils.rm("./app/graphql/types/edges/#{singularized_class_name}_edge.rb")
|
153
|
+
FileUtils.rm("./app/graphql/types/connections/#{singularized_class_name}_connection.rb")
|
154
|
+
FileUtils.rm("./spec/factories/#{pluralized_class_name}.rb")
|
155
|
+
FileUtils.rm("./spec/mutations/base/#{singularized_class_name}_spec.rb")
|
156
|
+
FileUtils.rm("./spec/models/#{singularized_class_name}_spec.rb")
|
157
|
+
FileUtils.rm("./spec/queries/#{singularized_class_name}_spec.rb")
|
158
|
+
FileUtils.rm("./spec/policies/#{singularized_class_name}_policy_spec.rb")
|
159
|
+
FileUtils.rm("./spec/resolvers/#{singularized_class_name}_search_spec.rb")
|
160
|
+
puts(Paint["deleted #{class_name.camelize} CRUD!", :yellow])
|
161
|
+
rescue StandardError => e
|
162
|
+
raise(StandardError, e)
|
163
|
+
end
|
162
164
|
end
|
163
165
|
end
|
164
166
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Souls
|
2
2
|
module Api::Generate
|
3
|
-
def self.connection(class_name: "
|
3
|
+
def self.connection(class_name: "user")
|
4
4
|
file_dir = "./app/graphql/types/connections/"
|
5
5
|
FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
|
6
6
|
singularized_class_name = class_name.underscore.singularize
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Souls
|
2
2
|
module Api::Generate
|
3
|
-
def self.edge(class_name: "
|
3
|
+
def self.edge(class_name: "user")
|
4
4
|
file_dir = "./app/graphql/types/edges"
|
5
5
|
FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
|
6
6
|
singularized_class_name = class_name.underscore.singularize
|
@@ -2,7 +2,7 @@ module Souls
|
|
2
2
|
module Api
|
3
3
|
module Generate
|
4
4
|
## Generate Model
|
5
|
-
def self.model(class_name: "
|
5
|
+
def self.model(class_name: "user")
|
6
6
|
file_dir = "./app/models/"
|
7
7
|
FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
|
8
8
|
file_path = "#{file_dir}#{class_name.singularize}.rb"
|
@@ -2,285 +2,287 @@ module Souls
|
|
2
2
|
module Api::Generate
|
3
3
|
## Generate 4 Mutations - ["create", "update", "delete", "destroy_delete"]
|
4
4
|
## 1.Mutation - Create
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
module
|
14
|
-
|
15
|
-
|
16
|
-
|
5
|
+
class << self
|
6
|
+
def create_mutation_head(class_name: "user")
|
7
|
+
singularized_class_name = class_name.singularize.underscore
|
8
|
+
dir_name = "./app/graphql/mutations/base/#{singularized_class_name}"
|
9
|
+
FileUtils.mkdir_p(dir_name) unless Dir.exist?(dir_name)
|
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
|
17
18
|
|
18
|
-
|
19
|
+
TEXT
|
20
|
+
end
|
21
|
+
file_path
|
19
22
|
end
|
20
|
-
file_path
|
21
|
-
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
24
|
+
def create_mutation_params(class_name: "user")
|
25
|
+
file_path = "./app/graphql/mutations/base/#{class_name}/create_#{class_name}.rb"
|
26
|
+
path = "./db/schema.rb"
|
27
|
+
@on = false
|
28
|
+
@user_exist = false
|
29
|
+
@relation_params = []
|
30
|
+
File.open(file_path, "a") do |new_line|
|
31
|
+
File.open(path, "r") do |f|
|
32
|
+
f.each_line.with_index do |line, _i|
|
33
|
+
if @on
|
34
|
+
if line.include?("t.index") || line.strip == "end"
|
35
|
+
if @user_exist
|
36
|
+
new_line.write(<<-TEXT)
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
def resolve **args
|
39
|
+
args[:user_id] = context[:user].id
|
40
|
+
TEXT
|
41
|
+
else
|
42
|
+
new_line.write(<<-TEXT)
|
42
43
|
|
43
|
-
|
44
|
-
|
44
|
+
def resolve **args
|
45
|
+
TEXT
|
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 ||= 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")
|
45
62
|
end
|
46
|
-
break
|
47
|
-
end
|
48
|
-
field = "[String]" if line.include?("array: true")
|
49
|
-
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
50
|
-
field ||= type_check(type)
|
51
|
-
case name
|
52
|
-
when "user_id"
|
53
|
-
@user_exist = true
|
54
|
-
when /$*_id\z/
|
55
|
-
@relation_params << name
|
56
|
-
new_line.write(" argument :#{name}, String, required: false\n")
|
57
|
-
when "created_at", "updated_at"
|
58
|
-
next
|
59
|
-
else
|
60
|
-
new_line.write(" argument :#{name}, #{field}, required: false\n")
|
61
63
|
end
|
64
|
+
@on = true if table_check(line: line, class_name: class_name)
|
62
65
|
end
|
63
|
-
@on = true if table_check(line: line, class_name: class_name)
|
64
66
|
end
|
65
67
|
end
|
68
|
+
@relation_params
|
66
69
|
end
|
67
|
-
@relation_params
|
68
|
-
end
|
69
70
|
|
70
|
-
|
71
|
-
|
71
|
+
def create_mutation_after_params(class_name: "user", relation_params: [])
|
72
|
+
return false if relation_params.empty?
|
72
73
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
74
|
+
file_path = "./app/graphql/mutations/base/#{class_name}/create_#{class_name}.rb"
|
75
|
+
relation_params.each do |params_name|
|
76
|
+
File.open(file_path, "a") do |new_line|
|
77
|
+
new_line.write(" _, args[:#{params_name}] = SoulsApiSchema.from_global_id(args[:#{params_name}])\n")
|
78
|
+
end
|
77
79
|
end
|
80
|
+
true
|
78
81
|
end
|
79
|
-
true
|
80
|
-
end
|
81
82
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
83
|
+
def create_mutation_end(class_name: "user")
|
84
|
+
file_path = "./app/graphql/mutations/base/#{class_name}/create_#{class_name}.rb"
|
85
|
+
File.open(file_path, "a") do |new_line|
|
86
|
+
new_line.write(<<~TEXT)
|
87
|
+
data = ::#{class_name.camelize}.new args
|
88
|
+
raise(StandardError, data.errors.full_messages) unless data.save
|
88
89
|
|
89
|
-
|
90
|
-
|
91
|
-
|
90
|
+
{ #{class_name}_edge: { node: data } }
|
91
|
+
rescue StandardError => error
|
92
|
+
GraphQL::ExecutionError.new error
|
93
|
+
end
|
92
94
|
end
|
93
95
|
end
|
94
96
|
end
|
95
|
-
|
96
|
-
|
97
|
+
TEXT
|
98
|
+
end
|
99
|
+
file_path
|
97
100
|
end
|
98
|
-
file_path
|
99
|
-
end
|
100
101
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
102
|
+
## 2.Mutation - Update
|
103
|
+
def update_mutation_head(class_name: "user")
|
104
|
+
file_path = "./app/graphql/mutations/base/#{class_name}/update_#{class_name}.rb"
|
105
|
+
File.open(file_path, "w") do |new_line|
|
106
|
+
new_line.write(<<~TEXT)
|
107
|
+
module Mutations
|
108
|
+
module Base::#{class_name.camelize}
|
109
|
+
class Update#{class_name.camelize} < BaseMutation
|
110
|
+
field :#{class_name}_edge, Types::#{class_name.camelize}Type.edge_type, null: false
|
110
111
|
|
111
|
-
|
112
|
-
|
112
|
+
argument :id, String, required: true
|
113
|
+
TEXT
|
114
|
+
end
|
115
|
+
file_path
|
113
116
|
end
|
114
|
-
file_path
|
115
|
-
end
|
116
117
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
118
|
+
def update_mutation_params(class_name: "user")
|
119
|
+
file_path = "./app/graphql/mutations/base/#{class_name}/update_#{class_name}.rb"
|
120
|
+
path = "./db/schema.rb"
|
121
|
+
@on = false
|
122
|
+
@user_exist = false
|
123
|
+
@relation_params = []
|
124
|
+
File.open(file_path, "a") do |new_line|
|
125
|
+
File.open(path, "r") do |f|
|
126
|
+
f.each_line.with_index do |line, _i|
|
127
|
+
if @on
|
128
|
+
if line.include?("t.index") || line.strip == "end"
|
129
|
+
if @user_exist
|
130
|
+
new_line.write(<<-TEXT)
|
130
131
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
132
|
+
def resolve **args
|
133
|
+
args[:user_id] = context[:user].id
|
134
|
+
_, args[:id] = SoulsApiSchema.from_global_id(args[:id])
|
135
|
+
TEXT
|
136
|
+
else
|
137
|
+
new_line.write(<<-TEXT)
|
137
138
|
|
138
|
-
|
139
|
-
|
140
|
-
|
139
|
+
def resolve **args
|
140
|
+
_, args[:id] = SoulsApiSchema.from_global_id(args[:id])
|
141
|
+
TEXT
|
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 ||= 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")
|
141
158
|
end
|
142
|
-
break
|
143
|
-
end
|
144
|
-
field = "[String]" if line.include?("array: true")
|
145
|
-
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
146
|
-
field ||= type_check(type)
|
147
|
-
case name
|
148
|
-
when "user_id"
|
149
|
-
@user_exist = true
|
150
|
-
when /$*_id\z/
|
151
|
-
@relation_params << name
|
152
|
-
new_line.write(" argument :#{name}, String, required: false\n")
|
153
|
-
when "created_at", "updated_at"
|
154
|
-
next
|
155
|
-
else
|
156
|
-
new_line.write(" argument :#{name}, #{field}, required: false\n")
|
157
159
|
end
|
160
|
+
@on = true if table_check(line: line, class_name: class_name)
|
158
161
|
end
|
159
|
-
@on = true if table_check(line: line, class_name: class_name)
|
160
162
|
end
|
161
163
|
end
|
164
|
+
@relation_params
|
162
165
|
end
|
163
|
-
@relation_params
|
164
|
-
end
|
165
166
|
|
166
|
-
|
167
|
-
|
167
|
+
def update_mutation_after_params(class_name: "article", relation_params: [])
|
168
|
+
return false if relation_params.empty?
|
168
169
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
170
|
+
file_path = "./app/graphql/mutations/base/#{class_name}/update_#{class_name}.rb"
|
171
|
+
relation_params.each do |params_name|
|
172
|
+
File.open(file_path, "a") do |new_line|
|
173
|
+
new_line.write(" _, args[:#{params_name}] = SoulsApiSchema.from_global_id(args[:#{params_name}])\n")
|
174
|
+
end
|
173
175
|
end
|
176
|
+
true
|
174
177
|
end
|
175
|
-
true
|
176
|
-
end
|
177
178
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
179
|
+
def update_mutation_end(class_name: "user")
|
180
|
+
file_path = "./app/graphql/mutations/base/#{class_name}/update_#{class_name}.rb"
|
181
|
+
File.open(file_path, "a") do |new_line|
|
182
|
+
new_line.write(<<~TEXT)
|
183
|
+
#{class_name} = ::#{class_name.camelize}.find args[:id]
|
184
|
+
#{class_name}.update args
|
185
|
+
{ #{class_name}_edge: { node: ::#{class_name.camelize}.find(args[:id]) } }
|
186
|
+
rescue StandardError => error
|
187
|
+
GraphQL::ExecutionError.new error
|
188
|
+
end
|
187
189
|
end
|
188
190
|
end
|
189
191
|
end
|
190
|
-
|
191
|
-
|
192
|
+
TEXT
|
193
|
+
end
|
194
|
+
file_path
|
192
195
|
end
|
193
|
-
file_path
|
194
|
-
end
|
195
196
|
|
196
|
-
|
197
|
-
|
198
|
-
|
197
|
+
def update_mutation(class_name: "user")
|
198
|
+
file_path = "./app/graphql/mutations/base/#{class_name}/update_#{class_name}.rb"
|
199
|
+
return "Mutation already exist! #{file_path}" if File.exist?(file_path)
|
199
200
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
201
|
+
update_mutation_head(class_name: class_name)
|
202
|
+
relation_params = update_mutation_params(class_name: class_name)
|
203
|
+
update_mutation_after_params(class_name: class_name, relation_params: relation_params)
|
204
|
+
update_mutation_end(class_name: class_name)
|
205
|
+
end
|
205
206
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
207
|
+
# 3. Mutation - Delete
|
208
|
+
def delete_mutation(class_name: "user")
|
209
|
+
file_path = "./app/graphql/mutations/base/#{class_name}/delete_#{class_name}.rb"
|
210
|
+
return "Mutation already exist! #{file_path}" if File.exist?(file_path)
|
210
211
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
212
|
+
File.open(file_path, "w") do |f|
|
213
|
+
f.write(<<~TEXT)
|
214
|
+
module Mutations
|
215
|
+
module Base::#{class_name.camelize}
|
216
|
+
class Delete#{class_name.camelize} < BaseMutation
|
217
|
+
field :#{class_name}, Types::#{class_name.camelize}Type, null: false
|
218
|
+
argument :id, String, required: true
|
218
219
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
220
|
+
def resolve **args
|
221
|
+
_, data_id = SoulsApiSchema.from_global_id args[:id]
|
222
|
+
#{class_name} = ::#{class_name.camelize}.find data_id
|
223
|
+
#{class_name}.update(is_deleted: true)
|
224
|
+
{ #{class_name}: ::#{class_name.camelize}.find(data_id) }
|
225
|
+
rescue StandardError => error
|
226
|
+
GraphQL::ExecutionError.new error
|
227
|
+
end
|
226
228
|
end
|
227
229
|
end
|
228
230
|
end
|
229
|
-
|
230
|
-
|
231
|
+
TEXT
|
232
|
+
end
|
233
|
+
file_path
|
231
234
|
end
|
232
|
-
file_path
|
233
|
-
end
|
234
235
|
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
236
|
+
# 4. Mutation - Destroy Delete
|
237
|
+
def destroy_delete_mutation(class_name: "user")
|
238
|
+
file_path = "./app/graphql/mutations/base/#{class_name}/destroy_delete_#{class_name}.rb"
|
239
|
+
return "Mutation already exist! #{file_path}" if File.exist?(file_path)
|
239
240
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
241
|
+
File.open(file_path, "w") do |f|
|
242
|
+
f.write(<<~TEXT)
|
243
|
+
module Mutations
|
244
|
+
module Base::#{class_name.camelize}
|
245
|
+
class DestroyDelete#{class_name.camelize} < BaseMutation
|
246
|
+
field :#{class_name}, Types::#{class_name.camelize}Type, null: false
|
247
|
+
argument :id, String, required: true
|
247
248
|
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
249
|
+
def resolve **args
|
250
|
+
_, data_id = SoulsApiSchema.from_global_id args[:id]
|
251
|
+
#{class_name} = ::#{class_name.camelize}.find data_id
|
252
|
+
#{class_name}.destroy
|
253
|
+
{ #{class_name}: #{class_name} }
|
254
|
+
rescue StandardError => error
|
255
|
+
GraphQL::ExecutionError.new error
|
256
|
+
end
|
255
257
|
end
|
256
258
|
end
|
257
259
|
end
|
258
|
-
|
259
|
-
|
260
|
+
TEXT
|
261
|
+
end
|
262
|
+
file_path
|
263
|
+
rescue StandardError => e
|
264
|
+
puts(e)
|
260
265
|
end
|
261
|
-
file_path
|
262
|
-
rescue StandardError => e
|
263
|
-
puts(e)
|
264
|
-
end
|
265
266
|
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
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)
|
272
273
|
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
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)
|
285
|
+
end
|
284
286
|
end
|
285
287
|
end
|
286
288
|
end
|