souls 0.64.3 → 0.65.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73e33f00be1dd636e4ecb2bfa311e4b893643b75dde7264763fb86f8d2e6f7e5
|
4
|
+
data.tar.gz: 34a0d428e24d4040e6010a2d6166914b1489790272b95cb9d0522c81f0b7ff06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 411130be7a78c60cb8e0284d2ffa655c362d1fbb5a73ae68a70608835abe481d93c571ccafdb816e04b05a24012e3c44ca8020855eb5264f2e573d604cee0982
|
7
|
+
data.tar.gz: 10eca27e01886d6d83073186ff82ab594b0277eafd37862b51a51a14ce4753372b49a5ff10fea8c2264779cc003bc69e9d4f1f0bca554dd81eb28d696d833f73
|
@@ -89,94 +89,64 @@ module Souls
|
|
89
89
|
file_path
|
90
90
|
end
|
91
91
|
|
92
|
-
|
93
|
-
def update_mutation_head(class_name: "user")
|
92
|
+
def update_mutation(class_name: "user")
|
94
93
|
singularized_class_name = class_name.singularize.underscore
|
95
94
|
file_dir = "./app/graphql/mutations/base/#{singularized_class_name}"
|
96
|
-
|
97
|
-
|
98
|
-
|
95
|
+
FileUtils.mkdir_p(file_dir) unless Dir.exist?(file_dir)
|
96
|
+
file_path = "#{file_dir}/update_#{singularized_class_name}.rb"
|
97
|
+
raise(Thor::Error, "Mutation RBS already exist! #{file_path}") if File.exist?(file_path)
|
98
|
+
|
99
|
+
params = Souls.get_relation_params(class_name: singularized_class_name, col: "mutation")
|
100
|
+
File.open(file_path, "w") do |f|
|
101
|
+
f.write(<<~TEXT)
|
99
102
|
module Mutations
|
100
|
-
module Base::#{
|
101
|
-
class Update#{
|
102
|
-
field :#{
|
103
|
+
module Base::#{singularized_class_name.camelize}
|
104
|
+
class Update#{singularized_class_name.camelize} < BaseMutation
|
105
|
+
field :#{singularized_class_name}_edge, Types::#{singularized_class_name.camelize}Type.edge_type, null: false
|
106
|
+
field :error, String, null: true
|
103
107
|
|
104
|
-
argument :id, String, required: true
|
105
108
|
TEXT
|
106
109
|
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
|
-
|
124
|
-
def resolve args
|
125
|
-
params = args.dup
|
126
|
-
params[:user_id] = context[:user][:id]
|
127
|
-
_, params[:id] = SoulsApiSchema.from_global_id(args[:id])
|
128
|
-
TEXT
|
129
|
-
else
|
130
|
-
new_line.write(<<-TEXT)
|
131
110
|
|
132
|
-
|
133
|
-
params
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
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)
|
111
|
+
File.open(file_path, "a") do |f|
|
112
|
+
params[:params].each_with_index do |param, i|
|
113
|
+
type = Souls.type_check(param[:type])
|
114
|
+
type = "[#{type}]" if param[:array]
|
115
|
+
type = "String" if param[:column_name].match?(/$*_id\z/)
|
116
|
+
if i == params[:params].size - 1
|
117
|
+
f.write(" argument :#{param[:column_name]}, #{type}, required: false\n\n")
|
118
|
+
f.write(" def resolve(args)\n")
|
119
|
+
else
|
120
|
+
f.write(" argument :#{param[:column_name]}, #{type}, required: false\n")
|
155
121
|
end
|
156
122
|
end
|
157
123
|
end
|
158
|
-
@relation_params
|
159
|
-
end
|
160
124
|
|
161
|
-
|
162
|
-
|
125
|
+
File.open(file_path, "a") do |f|
|
126
|
+
if params[:relation_params]
|
127
|
+
f.write(" user_id = context[:user][:id]\n") if params[:user_exist]
|
128
|
+
params[:relation_params].each_with_index do |col, _i|
|
129
|
+
next if col[:column_name] == "user_id"
|
163
130
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
131
|
+
f.write(" _, #{col[:column_name]} = SoulsApiSchema.from_global_id(args[:#{col[:column_name]}])\n")
|
132
|
+
end
|
133
|
+
relation_params =
|
134
|
+
params[:relation_params].map do |n|
|
135
|
+
", #{n[:column_name]}: #{n[:column_name]}"
|
136
|
+
end
|
137
|
+
f.write(" new_record = { **args #{relation_params.compact.join} }\n")
|
138
|
+
f.write(" data = ::#{singularized_class_name.camelize}.find(article_id)\n")
|
139
|
+
f.write(" data.update(new_record)\n")
|
140
|
+
else
|
141
|
+
f.write(" data = ::#{singularized_class_name.camelize}.find(article_id)\n")
|
142
|
+
f.write(" data.update(args)\n")
|
168
143
|
end
|
169
144
|
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
145
|
File.open(file_path, "a") do |new_line|
|
176
146
|
new_line.write(<<~TEXT)
|
177
|
-
|
178
|
-
|
179
|
-
{ #{
|
147
|
+
raise(StandardError, data.errors.full_messages) unless data.save
|
148
|
+
|
149
|
+
{ #{singularized_class_name}_edge: { node: data } }
|
180
150
|
rescue StandardError => error
|
181
151
|
GraphQL::ExecutionError.new(error.message)
|
182
152
|
end
|
@@ -189,16 +159,6 @@ module Souls
|
|
189
159
|
file_path
|
190
160
|
end
|
191
161
|
|
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
162
|
# 3. Mutation - Delete
|
203
163
|
def delete_mutation(class_name: "user")
|
204
164
|
file_path = "./app/graphql/mutations/base/#{class_name}/delete_#{class_name}.rb"
|
@@ -26,6 +26,9 @@ module Souls
|
|
26
26
|
rbs_type = Souls.rbs_type_check(param[:type])
|
27
27
|
if i.zero?
|
28
28
|
f.write(" def self.field: (:#{param[:column_name]}, #{type}, null: true) -> #{rbs_type}\n")
|
29
|
+
elsif param[:column_name].match?(/$*_id\z/)
|
30
|
+
col_name = param[:column_name].gsub("_id", "")
|
31
|
+
f.write(" def self.field: (:#{col_name}, untyped, null: false) -> untyped\n")
|
29
32
|
else
|
30
33
|
f.write(" | (:#{param[:column_name]}, #{type}, null: true) -> #{rbs_type}\n")
|
31
34
|
end
|
data/lib/souls/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.44.0
|
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.44.0
|