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: a3a33999e189283758881dbe8f9d0a7222580ca0b359363d845142aecc6faf63
4
- data.tar.gz: addf19b1163e5ae31937b0fe49ce464ed4de286d1edc013385a968dd721f858d
3
+ metadata.gz: 73e33f00be1dd636e4ecb2bfa311e4b893643b75dde7264763fb86f8d2e6f7e5
4
+ data.tar.gz: 34a0d428e24d4040e6010a2d6166914b1489790272b95cb9d0522c81f0b7ff06
5
5
  SHA512:
6
- metadata.gz: f19ae2ed49b96c8ac03e5944c79ac9f0cd8da0a4e7875660c83236c0cc645c16f064c4f97fa53d1b7c9ee3ae61ad9648c1cd3a4f84c038034ed57743cca7edc2
7
- data.tar.gz: e95ee79d899afb8a255018c6d0da216e400f0689690cb2d1cc4a83f30c644ee7f2d7d35597f17a0ab07db1e887b1e0b29e7d786c51ab6d620351384f07b65d8d
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
- ## 2.Mutation - Update
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
- file_path = "#{file_dir}/update_#{class_name}.rb"
97
- File.open(file_path, "w") do |new_line|
98
- new_line.write(<<~TEXT)
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::#{class_name.camelize}
101
- class Update#{class_name.camelize} < BaseMutation
102
- field :#{class_name}_edge, Types::#{class_name.camelize}Type.edge_type, null: false
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
- def resolve args
133
- params = args.dup
134
- _, params[:id] = SoulsApiSchema.from_global_id(args[:id])
135
- TEXT
136
- end
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)
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
- def update_mutation_after_params(class_name: "article", relation_params: [])
162
- return false if relation_params.empty?
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
- file_path = "./app/graphql/mutations/base/#{class_name}/update_#{class_name}.rb"
165
- relation_params.each do |params_name|
166
- File.open(file_path, "a") do |new_line|
167
- new_line.write(" _, params[:#{params_name}] = SoulsApiSchema.from_global_id(args[:#{params_name}])\n")
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
- #{class_name} = ::#{class_name.camelize}.find params[:id]
178
- #{class_name}.update params
179
- { #{class_name}_edge: { node: ::#{class_name.camelize}.find(params[:id]) } }
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,4 +1,4 @@
1
1
  module Souls
2
- VERSION = "0.64.3".freeze
2
+ VERSION = "0.65.0".freeze
3
3
  public_constant :VERSION
4
4
  end
@@ -1 +1 @@
1
- 0.43.3
1
+ 0.44.0
@@ -1 +1 @@
1
- 0.43.3
1
+ 0.44.0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: souls
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.64.3
4
+ version: 0.65.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - POPPIN-FUMI