souls 0.44.6 → 0.45.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d865b08288f0e499cfb249f6fe2a40f3c638c29c4926b7f3897d0b623c0ec18c
4
- data.tar.gz: bec91ce65113d32ebd75e3b13e523be4349717aa8a2eb0afd1fd2633f8a46d12
3
+ metadata.gz: d57e23a96220bb12f1e05e04d14ec61e235135aaca9dad88649b1b7ff76a1fa9
4
+ data.tar.gz: 4501314bd172a0f83bc594bbf1d5efcaf8280464719e897835da63fc6c273a2f
5
5
  SHA512:
6
- metadata.gz: 02b279c8eaa243c5ae867565ffa321a9ffcf14379a43985317e19a8674c817a48fd551c00f23f3714bb390b2d62e5b50e4cbfd101a3a520301191f2b9f6bd261
7
- data.tar.gz: e5717306a70cbfe4824a9e9eac97f78f344ff92bd564df03001b21c54d6d201467118c80bfd3ef0337ecabcb86e159b7fb6b45d96a864df0d658b2c0ef539d40
6
+ metadata.gz: eb881eb7b44c13a76bf3f5084d6565c665e820c2ca27e2cd0932b9c6b81f35b26ee2091273ba350adf9cf0fcfedef219fd993ed3b109d0ccc5b47937c32e59ef
7
+ data.tar.gz: 734e41bf5578176220d906eed0ed4dc717d185a328f9e621a3a856fc295025534f4b62ebdfdf979f3c28862815cc16fc555b2819ed5a1647c661ef0d3101e68b
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 3 types of framework.
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
 
@@ -1,164 +1,166 @@
1
1
  module Souls
2
2
  module Api::Generate
3
3
  ## Common Methods
4
- def self.generated_paths(class_name: "user")
5
- singularized_class_name = class_name.singularize.underscore
6
- pluralized_class_name = class_name.pluralize.underscore
7
- [
8
- "./app/models/#{singularized_class_name}.rb",
9
- "./app/policies/#{singularized_class_name}_policy.rb",
10
- "./app/graphql/mutations/create_#{singularized_class_name}.rb",
11
- "./app/graphql/mutations/delete_#{singularized_class_name}.rb",
12
- "./app/graphql/mutations/destroy_delete_#{singularized_class_name}.rb",
13
- "./app/graphql/mutations/update_#{singularized_class_name}.rb",
14
- "./app/graphql/queries/#{singularized_class_name}.rb",
15
- "./app/graphql/queries/#{pluralized_class_name}.rb",
16
- "./app/graphql/resolvers/#{singularized_class_name}_search.rb",
17
- "./app/graphql/types/#{singularized_class_name}_type.rb",
18
- "./app/graphql/types/edges/#{singularized_class_name}_edge.rb",
19
- "./app/graphql/types/connections/#{singularized_class_name}_connection.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
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
- def self.get_type_and_name(line)
30
- line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
31
- end
30
+ def get_type_and_name(line)
31
+ line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
32
+ end
32
33
 
33
- def self.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")
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
- def self.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
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
- def self.type_check(type)
65
- {
66
- bigint: "Integer",
67
- string: "String",
68
- float: "Float",
69
- text: "String",
70
- datetime: "String",
71
- date: "String",
72
- boolean: "Boolean",
73
- integer: "Integer"
74
- }[type.to_sym]
75
- end
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
- def self.get_type(type)
78
- {
79
- bigint: "Integer",
80
- string: "String",
81
- float: "Float",
82
- text: "String",
83
- datetime: "GraphQL::Types::ISO8601DateTime",
84
- date: "GraphQL::Types::ISO8601DateTime",
85
- boolean: "Boolean",
86
- integer: "Integer"
87
- }[type.to_sym]
88
- end
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
- def self.get_test_type(type)
91
- {
92
- bigint: "rand(1..10)",
93
- float: 4.2,
94
- string: '"MyString"',
95
- text: '"MyString"',
96
- datetime: "Time.now",
97
- date: "Time.now.strftime('%F')",
98
- boolean: false,
99
- integer: "rand(1..10)"
100
- }[type.to_sym]
101
- end
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
- def self.table_check(line: "", class_name: "")
104
- if line.include?("create_table") && (line.split[1].gsub("\"", "").gsub(",", "") == class_name.pluralize.to_s)
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
- return true
107
- end
107
+ return true
108
+ end
108
109
 
109
- false
110
- end
110
+ false
111
+ end
111
112
 
112
- def self.scaffold(class_name: "souls")
113
- singularized_class_name = class_name.singularize
114
- model(class_name: singularized_class_name)
115
- type(class_name: singularized_class_name)
116
- edge(class_name: singularized_class_name)
117
- connection(class_name: singularized_class_name)
118
- resolver(class_name: singularized_class_name)
119
- rspec_factory(class_name: singularized_class_name)
120
- rspec_model(class_name: singularized_class_name)
121
- rspec_mutation(class_name: singularized_class_name)
122
- rspec_query(class_name: singularized_class_name)
123
- rspec_resolver(class_name: singularized_class_name)
124
- query(class_name: singularized_class_name)
125
- mutation(class_name: singularized_class_name)
126
- policy(class_name: singularized_class_name)
127
- rspec_policy(class_name: singularized_class_name)
128
- rescue StandardError => e
129
- puts(e.backtrace)
130
- raise(StandardError, e)
131
- end
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
- def self.scaffold_all
134
- puts(Paint["Let's Go SOULs AUTO CRUD Assist!\n", :cyan])
135
- Souls::Api::Generate.get_tables.each do |table|
136
- Souls::Api::Generate.scaffold(class_name: table.singularize)
137
- puts(Paint["Generated #{table.camelize} CRUD Files\n", :yellow])
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
- def self.delete_all(class_name: "souls")
142
- singularized_class_name = class_name.singularize.underscore
143
- pluralized_class_name = class_name.pluralize.underscore
144
- FileUtils.rm("./app/models/#{singularized_class_name}.rb")
145
- FileUtils.rm("./app/policies/#{singularized_class_name}_policy.rb")
146
- FileUtils.rm_rf("./app/graphql/mutations/base/#{singularized_class_name}")
147
- FileUtils.rm("./app/graphql/queries/#{singularized_class_name}.rb")
148
- FileUtils.rm("./app/graphql/queries/#{pluralized_class_name}.rb")
149
- FileUtils.rm("./app/graphql/resolvers/#{singularized_class_name}_search.rb")
150
- FileUtils.rm("./app/graphql/types/#{singularized_class_name}_type.rb")
151
- FileUtils.rm("./app/graphql/types/edges/#{singularized_class_name}_edge.rb")
152
- FileUtils.rm("./app/graphql/types/connections/#{singularized_class_name}_connection.rb")
153
- FileUtils.rm("./spec/factories/#{pluralized_class_name}.rb")
154
- FileUtils.rm("./spec/mutations/base/#{singularized_class_name}_spec.rb")
155
- FileUtils.rm("./spec/models/#{singularized_class_name}_spec.rb")
156
- FileUtils.rm("./spec/queries/#{singularized_class_name}_spec.rb")
157
- FileUtils.rm("./spec/policies/#{singularized_class_name}_policy_spec.rb")
158
- FileUtils.rm("./spec/resolvers/#{singularized_class_name}_search_spec.rb")
159
- puts(Paint["deleted #{class_name.camelize} CRUD!", :yellow])
160
- rescue StandardError => e
161
- raise(StandardError, e)
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: "souls")
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: "souls")
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: "souls")
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
- def self.create_mutation_head(class_name: "user")
6
- singularized_class_name = class_name.singularize.underscore
7
- dir_name = "./app/graphql/mutations/base/#{singularized_class_name}"
8
- FileUtils.mkdir_p(dir_name) unless Dir.exist?(dir_name)
9
- file_path = "./app/graphql/mutations/base/#{singularized_class_name}/create_#{singularized_class_name}.rb"
10
- File.open(file_path, "w") do |new_line|
11
- new_line.write(<<~TEXT)
12
- module Mutations
13
- module Base::#{singularized_class_name.camelize}
14
- class Create#{singularized_class_name.camelize} < BaseMutation
15
- field :#{singularized_class_name}_edge, Types::#{singularized_class_name.camelize}Type.edge_type, null: false
16
- field :error, String, null: true
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
- TEXT
19
+ TEXT
20
+ end
21
+ file_path
19
22
  end
20
- file_path
21
- end
22
23
 
23
- def self.create_mutation_params(class_name: "user")
24
- file_path = "./app/graphql/mutations/base/#{class_name}/create_#{class_name}.rb"
25
- path = "./db/schema.rb"
26
- @on = false
27
- @user_exist = false
28
- @relation_params = []
29
- File.open(file_path, "a") do |new_line|
30
- File.open(path, "r") do |f|
31
- f.each_line.with_index do |line, _i|
32
- if @on
33
- if line.include?("t.index") || line.strip == "end"
34
- if @user_exist
35
- new_line.write(<<-TEXT)
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
- def resolve **args
38
- args[:user_id] = context[:user].id
39
- TEXT
40
- else
41
- new_line.write(<<-TEXT)
38
+ def resolve **args
39
+ args[:user_id] = context[:user].id
40
+ TEXT
41
+ else
42
+ new_line.write(<<-TEXT)
42
43
 
43
- def resolve **args
44
- TEXT
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
- def self.create_mutation_after_params(class_name: "user", relation_params: [])
71
- return false if relation_params.empty?
71
+ def create_mutation_after_params(class_name: "user", relation_params: [])
72
+ return false if relation_params.empty?
72
73
 
73
- file_path = "./app/graphql/mutations/base/#{class_name}/create_#{class_name}.rb"
74
- relation_params.each do |params_name|
75
- File.open(file_path, "a") do |new_line|
76
- new_line.write(" _, args[:#{params_name}] = SoulsApiSchema.from_global_id(args[:#{params_name}])\n")
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
- def self.create_mutation_end(class_name: "user")
83
- file_path = "./app/graphql/mutations/base/#{class_name}/create_#{class_name}.rb"
84
- File.open(file_path, "a") do |new_line|
85
- new_line.write(<<~TEXT)
86
- data = ::#{class_name.camelize}.new args
87
- raise(StandardError, data.errors.full_messages) unless data.save
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
- { #{class_name}_edge: { node: data } }
90
- rescue StandardError => error
91
- GraphQL::ExecutionError.new error
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
- end
96
- TEXT
97
+ TEXT
98
+ end
99
+ file_path
97
100
  end
98
- file_path
99
- end
100
101
 
101
- ## 2.Mutation - Update
102
- def self.update_mutation_head(class_name: "user")
103
- file_path = "./app/graphql/mutations/base/#{class_name}/update_#{class_name}.rb"
104
- File.open(file_path, "w") do |new_line|
105
- new_line.write(<<~TEXT)
106
- module Mutations
107
- module Base::#{class_name.camelize}
108
- class Update#{class_name.camelize} < BaseMutation
109
- field :#{class_name}_edge, Types::#{class_name.camelize}Type.edge_type, null: false
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
- argument :id, String, required: true
112
- TEXT
112
+ argument :id, String, required: true
113
+ TEXT
114
+ end
115
+ file_path
113
116
  end
114
- file_path
115
- end
116
117
 
117
- def self.update_mutation_params(class_name: "user")
118
- file_path = "./app/graphql/mutations/base/#{class_name}/update_#{class_name}.rb"
119
- path = "./db/schema.rb"
120
- @on = false
121
- @user_exist = false
122
- @relation_params = []
123
- File.open(file_path, "a") do |new_line|
124
- File.open(path, "r") do |f|
125
- f.each_line.with_index do |line, _i|
126
- if @on
127
- if line.include?("t.index") || line.strip == "end"
128
- if @user_exist
129
- new_line.write(<<-TEXT)
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
- def resolve **args
132
- args[:user_id] = context[:user].id
133
- _, args[:id] = SoulsApiSchema.from_global_id(args[:id])
134
- TEXT
135
- else
136
- new_line.write(<<-TEXT)
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
- def resolve **args
139
- _, args[:id] = SoulsApiSchema.from_global_id(args[:id])
140
- TEXT
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
- def self.update_mutation_after_params(class_name: "article", relation_params: [])
167
- return false if relation_params.empty?
167
+ def update_mutation_after_params(class_name: "article", relation_params: [])
168
+ return false if relation_params.empty?
168
169
 
169
- file_path = "./app/graphql/mutations/base/#{class_name}/update_#{class_name}.rb"
170
- relation_params.each do |params_name|
171
- File.open(file_path, "a") do |new_line|
172
- new_line.write(" _, args[:#{params_name}] = SoulsApiSchema.from_global_id(args[:#{params_name}])\n")
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
- def self.update_mutation_end(class_name: "user")
179
- file_path = "./app/graphql/mutations/base/#{class_name}/update_#{class_name}.rb"
180
- File.open(file_path, "a") do |new_line|
181
- new_line.write(<<~TEXT)
182
- #{class_name} = ::#{class_name.camelize}.find args[:id]
183
- #{class_name}.update args
184
- { #{class_name}_edge: { node: ::#{class_name.camelize}.find(args[:id]) } }
185
- rescue StandardError => error
186
- GraphQL::ExecutionError.new error
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
- end
191
- TEXT
192
+ TEXT
193
+ end
194
+ file_path
192
195
  end
193
- file_path
194
- end
195
196
 
196
- def self.update_mutation(class_name: "user")
197
- file_path = "./app/graphql/mutations/base/#{class_name}/update_#{class_name}.rb"
198
- return "Mutation already exist! #{file_path}" if File.exist?(file_path)
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
- update_mutation_head(class_name: class_name)
201
- relation_params = update_mutation_params(class_name: class_name)
202
- update_mutation_after_params(class_name: class_name, relation_params: relation_params)
203
- update_mutation_end(class_name: class_name)
204
- end
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
- # 3. Mutation - Delete
207
- def self.delete_mutation(class_name: "user")
208
- file_path = "./app/graphql/mutations/base/#{class_name}/delete_#{class_name}.rb"
209
- return "Mutation already exist! #{file_path}" if File.exist?(file_path)
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
- File.open(file_path, "w") do |f|
212
- f.write(<<~TEXT)
213
- module Mutations
214
- module Base::#{class_name.camelize}
215
- class Delete#{class_name.camelize} < BaseMutation
216
- field :#{class_name}, Types::#{class_name.camelize}Type, null: false
217
- argument :id, String, required: true
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
- def resolve **args
220
- _, data_id = SoulsApiSchema.from_global_id args[:id]
221
- #{class_name} = ::#{class_name.camelize}.find data_id
222
- #{class_name}.update(is_deleted: true)
223
- { #{class_name}: ::#{class_name.camelize}.find(data_id) }
224
- rescue StandardError => error
225
- GraphQL::ExecutionError.new error
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
- end
230
- TEXT
231
+ TEXT
232
+ end
233
+ file_path
231
234
  end
232
- file_path
233
- end
234
235
 
235
- # 4. Mutation - Destroy Delete
236
- def self.destroy_delete_mutation(class_name: "user")
237
- file_path = "./app/graphql/mutations/base/#{class_name}/destroy_delete_#{class_name}.rb"
238
- return "Mutation already exist! #{file_path}" if File.exist?(file_path)
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
- File.open(file_path, "w") do |f|
241
- f.write(<<~TEXT)
242
- module Mutations
243
- module Base::#{class_name.camelize}
244
- class DestroyDelete#{class_name.camelize} < BaseMutation
245
- field :#{class_name}, Types::#{class_name.camelize}Type, null: false
246
- argument :id, String, required: true
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
- def resolve **args
249
- _, data_id = SoulsApiSchema.from_global_id args[:id]
250
- #{class_name} = ::#{class_name.camelize}.find data_id
251
- #{class_name}.destroy
252
- { #{class_name}: #{class_name} }
253
- rescue StandardError => error
254
- GraphQL::ExecutionError.new error
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
- end
259
- TEXT
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
- def self.mutation(class_name: "user")
267
- singularized_class_name = class_name.singularize
268
- file_dir = "./app/graphql/mutations/base"
269
- FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
270
- file_path = "./app/graphql/mutations/base/#{singularized_class_name}/create_#{singularized_class_name}.rb"
271
- return "Mutation already exist! #{file_path}" if File.exist?(file_path)
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
- create_mutation_head(class_name: singularized_class_name)
274
- relation_params = create_mutation_params(class_name: singularized_class_name)
275
- create_mutation_after_params(class_name: singularized_class_name, relation_params: relation_params)
276
- create_mutation_end(class_name: singularized_class_name)
277
- update_mutation(class_name: singularized_class_name)
278
- delete_mutation(class_name: singularized_class_name)
279
- destroy_delete_mutation(class_name: singularized_class_name)
280
- puts(Paint % ["Created file! : %{white_text}", :green, { white_text: [file_path.to_s, :white] }])
281
- file_path
282
- rescue StandardError => e
283
- raise(StandardError, e)
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