souls 0.64.3 → 0.65.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/lib/souls/cli/generate/mutation.rb +45 -80
- data/lib/souls/cli/generate/mutation_rbs.rb +4 -0
- data/lib/souls/cli/generate/type_rbs.rb +9 -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
- 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: f067eba7f9bf393c19177e68748534be2a5a728543fa5962dc4e5bc11a8d89f4
|
4
|
+
data.tar.gz: 6f954ae664e35fe87252152d75c91ae13aa2da150ee5447c072b43cc8426c5c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72b65bc98b779719626ff4b95890da9ec4e0740a1eccb981c95de7346934c7e73a813e4ceaefec947c9d2b82fcd17a2e08ad09d111acbf4fe975831441be92e7
|
7
|
+
data.tar.gz: f341b2cba0d2223038a60be61c393e3ba5ce779947e1f0d1ad7aa065adac38c33139dc14f86d622649535033c96b9c00bea4950a19ab6fe210585355b481e483
|
@@ -45,6 +45,8 @@ module Souls
|
|
45
45
|
type = Souls.type_check(param[:type])
|
46
46
|
type = "[#{type}]" if param[:array]
|
47
47
|
type = "String" if param[:column_name].match?(/$*_id\z/)
|
48
|
+
next if params[:column_name] == "user_id"
|
49
|
+
|
48
50
|
if i == params[:params].size - 1
|
49
51
|
f.write(" argument :#{param[:column_name]}, #{type}, required: false\n\n")
|
50
52
|
f.write(" def resolve(args)\n")
|
@@ -89,94 +91,67 @@ module Souls
|
|
89
91
|
file_path
|
90
92
|
end
|
91
93
|
|
92
|
-
|
93
|
-
def update_mutation_head(class_name: "user")
|
94
|
+
def update_mutation(class_name: "user")
|
94
95
|
singularized_class_name = class_name.singularize.underscore
|
95
96
|
file_dir = "./app/graphql/mutations/base/#{singularized_class_name}"
|
96
|
-
|
97
|
-
|
98
|
-
|
97
|
+
FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
|
98
|
+
file_path = "#{file_dir}/update_#{singularized_class_name}.rb"
|
99
|
+
raise(Thor::Error, "Mutation RBS already exist! #{file_path}") if File.exist?(file_path)
|
100
|
+
|
101
|
+
params = Souls.get_relation_params(class_name: singularized_class_name, col: "mutation")
|
102
|
+
File.open(file_path, "w") do |f|
|
103
|
+
f.write(<<~TEXT)
|
99
104
|
module Mutations
|
100
|
-
module Base::#{
|
101
|
-
class Update#{
|
102
|
-
field :#{
|
105
|
+
module Base::#{singularized_class_name.camelize}
|
106
|
+
class Update#{singularized_class_name.camelize} < BaseMutation
|
107
|
+
field :#{singularized_class_name}_edge, Types::#{singularized_class_name.camelize}Type.edge_type, null: false
|
108
|
+
field :error, String, null: true
|
103
109
|
|
104
110
|
argument :id, String, required: true
|
105
111
|
TEXT
|
106
112
|
end
|
107
|
-
file_path
|
108
|
-
end
|
109
|
-
|
110
|
-
def update_mutation_params(class_name: "user")
|
111
|
-
file_path = "./app/graphql/mutations/base/#{class_name}/update_#{class_name}.rb"
|
112
|
-
path = "./db/schema.rb"
|
113
|
-
@on = false
|
114
|
-
@user_exist = false
|
115
|
-
@relation_params = []
|
116
|
-
File.open(file_path, "a") do |new_line|
|
117
|
-
File.open(path, "r") do |f|
|
118
|
-
f.each_line.with_index do |line, _i|
|
119
|
-
if @on
|
120
|
-
if line.include?("t.index") || line.strip == "end"
|
121
|
-
if @user_exist
|
122
|
-
new_line.write(<<-TEXT)
|
123
113
|
|
124
|
-
|
125
|
-
params
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
new_line.write(<<-TEXT)
|
114
|
+
File.open(file_path, "a") do |f|
|
115
|
+
params[:params].each_with_index do |param, i|
|
116
|
+
type = Souls.type_check(param[:type])
|
117
|
+
type = "[#{type}]" if param[:array]
|
118
|
+
type = "String" if param[:column_name].match?(/$*_id\z/)
|
119
|
+
next if col[:column_name] == "user_id"
|
131
120
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
break
|
138
|
-
end
|
139
|
-
field = "[String]" if line.include?("array: true")
|
140
|
-
type, name = line.split(",")[0].gsub("\"", "").scan(/((?<=t\.).+(?=\s)) (.+)/)[0]
|
141
|
-
field ||= Souls.type_check(type)
|
142
|
-
case name
|
143
|
-
when "user_id"
|
144
|
-
@user_exist = true
|
145
|
-
when /$*_id\z/
|
146
|
-
@relation_params << name
|
147
|
-
new_line.write(" argument :#{name}, String, required: false\n")
|
148
|
-
when "created_at", "updated_at"
|
149
|
-
next
|
150
|
-
else
|
151
|
-
new_line.write(" argument :#{name}, #{field}, required: false\n")
|
152
|
-
end
|
153
|
-
end
|
154
|
-
@on = true if Souls.table_check(line: line, class_name: class_name)
|
121
|
+
if i == params[:params].size - 1
|
122
|
+
f.write(" argument :#{param[:column_name]}, #{type}, required: false\n\n")
|
123
|
+
f.write(" def resolve(args)\n")
|
124
|
+
else
|
125
|
+
f.write(" argument :#{param[:column_name]}, #{type}, required: false\n")
|
155
126
|
end
|
156
127
|
end
|
157
128
|
end
|
158
|
-
@relation_params
|
159
|
-
end
|
160
129
|
|
161
|
-
|
162
|
-
|
130
|
+
File.open(file_path, "a") do |f|
|
131
|
+
if params[:relation_params]
|
132
|
+
f.write(" user_id = context[:user][:id]\n") if params[:user_exist]
|
133
|
+
params[:relation_params].each_with_index do |col, _i|
|
134
|
+
next if col[:column_name] == "user_id"
|
163
135
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
136
|
+
f.write(" _, #{col[:column_name]} = SoulsApiSchema.from_global_id(args[:#{col[:column_name]}])\n")
|
137
|
+
end
|
138
|
+
relation_params =
|
139
|
+
params[:relation_params].map do |n|
|
140
|
+
", #{n[:column_name]}: #{n[:column_name]}"
|
141
|
+
end
|
142
|
+
f.write(" new_record = { **args #{relation_params.compact.join} }\n")
|
143
|
+
f.write(" data = ::#{singularized_class_name.camelize}.find(article_id)\n")
|
144
|
+
f.write(" data.update(new_record)\n")
|
145
|
+
else
|
146
|
+
f.write(" data = ::#{singularized_class_name.camelize}.find(args[:id])\n")
|
147
|
+
f.write(" data.update(args)\n")
|
168
148
|
end
|
169
149
|
end
|
170
|
-
true
|
171
|
-
end
|
172
|
-
|
173
|
-
def update_mutation_end(class_name: "user")
|
174
|
-
file_path = "./app/graphql/mutations/base/#{class_name}/update_#{class_name}.rb"
|
175
150
|
File.open(file_path, "a") do |new_line|
|
176
151
|
new_line.write(<<~TEXT)
|
177
|
-
|
178
|
-
|
179
|
-
{ #{
|
152
|
+
raise(StandardError, data.errors.full_messages) unless data.save
|
153
|
+
|
154
|
+
{ #{singularized_class_name}_edge: { node: data } }
|
180
155
|
rescue StandardError => error
|
181
156
|
GraphQL::ExecutionError.new(error.message)
|
182
157
|
end
|
@@ -189,16 +164,6 @@ module Souls
|
|
189
164
|
file_path
|
190
165
|
end
|
191
166
|
|
192
|
-
def update_mutation(class_name: "user")
|
193
|
-
file_path = "./app/graphql/mutations/base/#{class_name}/update_#{class_name}.rb"
|
194
|
-
return "Mutation already exist! #{file_path}" if File.exist?(file_path)
|
195
|
-
|
196
|
-
update_mutation_head(class_name: class_name)
|
197
|
-
relation_params = update_mutation_params(class_name: class_name)
|
198
|
-
update_mutation_after_params(class_name: class_name, relation_params: relation_params)
|
199
|
-
update_mutation_end(class_name: class_name)
|
200
|
-
end
|
201
|
-
|
202
167
|
# 3. Mutation - Delete
|
203
168
|
def delete_mutation(class_name: "user")
|
204
169
|
file_path = "./app/graphql/mutations/base/#{class_name}/delete_#{class_name}.rb"
|
@@ -42,6 +42,8 @@ module Souls
|
|
42
42
|
type = "[#{type}]" if param[:array]
|
43
43
|
if i == params[:params].size - 1
|
44
44
|
f.write(" #{param[:column_name]}: #{type}?\n")
|
45
|
+
elsif param[:column_name].match?(/$*_id\z/)
|
46
|
+
f.write(" #{param[:column_name]}: String?,\n")
|
45
47
|
else
|
46
48
|
f.write(" #{param[:column_name]}: #{type}?,\n")
|
47
49
|
end
|
@@ -60,6 +62,8 @@ module Souls
|
|
60
62
|
type = "[#{type}]" if param[:array]
|
61
63
|
if i.zero?
|
62
64
|
f.write(" def self.argument: (:#{param[:column_name]}, #{type}, required: false ) -> #{rbs_type}\n")
|
65
|
+
elsif param[:column_name].match?(/$*_id\z/)
|
66
|
+
f.write(" | (:#{param[:column_name]}, String, required: false ) -> String\n")
|
63
67
|
else
|
64
68
|
f.write(" | (:#{param[:column_name]}, #{type}, required: false ) -> #{rbs_type}\n")
|
65
69
|
end
|
@@ -25,7 +25,15 @@ module Souls
|
|
25
25
|
type = "[#{type}]" if param[:array]
|
26
26
|
rbs_type = Souls.rbs_type_check(param[:type])
|
27
27
|
if i.zero?
|
28
|
-
|
28
|
+
if param[:column_name].match?(/$*_id\z/)
|
29
|
+
col_name = param[:column_name].gsub("_id", "")
|
30
|
+
f.write(" def self.field: (:#{col_name}, untyped, null: false) -> untyped\n")
|
31
|
+
else
|
32
|
+
f.write(" def self.field: (:#{param[:column_name]}, #{type}, null: true) -> #{rbs_type}\n")
|
33
|
+
end
|
34
|
+
elsif param[:column_name].match?(/$*_id\z/)
|
35
|
+
col_name = param[:column_name].gsub("_id", "")
|
36
|
+
f.write(" | (:#{col_name}, untyped, null: false) -> untyped\n")
|
29
37
|
else
|
30
38
|
f.write(" | (:#{param[:column_name]}, #{type}, null: true) -> #{rbs_type}\n")
|
31
39
|
end
|
data/lib/souls/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.44.3
|
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.44.3
|