ntq_tools 0.3.0 → 0.4.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: 6ae778a1b16f9e589fe5d85bc0cf643d83c6c4a86ef20e5280fa3cce218a9dca
|
4
|
+
data.tar.gz: 541dd2e07470a6d6498d6ff5a106f0b05d8a83434a3038ca4add643d5d44af96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76d4ec81c0b78de510676e498edc48befe7ce2a882ef62b0e4442dd38c30bbee28060cceac6bca145c086af3d39c1bec0fdd3b798b2aff823df69122ff3c3348
|
7
|
+
data.tar.gz: 530deba6cce227ff8764dd1c0458c904677ef984f147abda260b6ff039f7fef23802cacc3068851356583029cc0490b60f100b7d3378d30bf58c721dfee73cf7
|
@@ -60,7 +60,7 @@ module NtqTools
|
|
60
60
|
%i[belongs_to has_one].each do |association_type|
|
61
61
|
class_name.constantize.reflect_on_all_associations(association_type).each do |asso|
|
62
62
|
class_name = asso.options.dig(:class_name) || asso.name.to_s.singularize.camelcase
|
63
|
-
associations << "field :#{asso.name}, Types::#{class_name}Type"
|
63
|
+
associations << "field :#{asso.name}, Types::#{class_name.downcase.pluralize.camelcase}::#{class_name}Type"
|
64
64
|
end
|
65
65
|
end
|
66
66
|
[:has_many].each do |association_type|
|
@@ -68,7 +68,7 @@ module NtqTools
|
|
68
68
|
class_name = asso.options.dig(:class_name) || asso.name.to_s.singularize.camelcase
|
69
69
|
next if class_name == 'PaperTrail::Version'
|
70
70
|
|
71
|
-
associations << "field :#{asso.name}, [Types::#{class_name}Type]"
|
71
|
+
associations << "field :#{asso.name}, [Types::#{class_name.downcase.pluralize.camelcase}::#{class_name}Type]"
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -99,27 +99,20 @@ module InputObject
|
|
99
99
|
')}
|
100
100
|
end
|
101
101
|
end
|
102
|
-
FILE
|
103
|
-
|
104
|
-
# Attributes file
|
105
|
-
create_file "app/graphql/input_object/search_#{plural_name}_attributes.rb", <<~FILE
|
106
|
-
module InputObject
|
107
|
-
class Search#{plural_name.camelcase}Attributes < AttributesInputObject
|
108
|
-
|
109
|
-
end
|
110
|
-
end
|
111
102
|
FILE
|
112
103
|
|
113
104
|
# Create mutation
|
114
105
|
create_file "app/graphql/mutations/#{plural_name}/create_#{singular_name}.rb", <<~FILE
|
115
106
|
module Mutations
|
116
107
|
class #{plural_name.camelcase}::Create#{singular_name.camelcase} < BaseMutation
|
108
|
+
|
109
|
+
field :#{singular_name}, Types::#{plural_name.camelcase}::#{singular_name.camelcase}Type, null: false
|
117
110
|
field :flash_messages, [Types::JsonType], null: false
|
118
111
|
|
119
112
|
argument :attributes, InputObject::#{singular_name.camelcase}Attributes, required: true
|
120
113
|
|
121
114
|
def authorized?(attributes:)
|
122
|
-
context[:current_user].can?(:create, #{singular_name})
|
115
|
+
context[:current_user].can?(:create, #{singular_name.camelcase})
|
123
116
|
end
|
124
117
|
|
125
118
|
def resolve(attributes:)
|
@@ -144,7 +137,9 @@ FILE
|
|
144
137
|
create_file "app/graphql/mutations/#{plural_name}/update_#{singular_name}.rb", <<~FILE
|
145
138
|
module Mutations
|
146
139
|
class #{plural_name.camelcase}::Update#{singular_name.camelcase} < BaseMutation
|
147
|
-
|
140
|
+
|
141
|
+
field :#{singular_name}, Types::#{plural_name.camelcase}::#{singular_name.camelcase}Type, null: false
|
142
|
+
field :flash_messages, [Types::JsonType], null: true
|
148
143
|
|
149
144
|
argument :id, ID, required: true
|
150
145
|
argument :attributes, InputObject::#{singular_name.camelcase}Attributes, required: true
|
@@ -159,8 +154,8 @@ FILE
|
|
159
154
|
#{singular_name}.attributes = attributes
|
160
155
|
#{singular_name}.save!
|
161
156
|
{
|
157
|
+
#{singular_name}: #{singular_name},
|
162
158
|
flash_messages: [
|
163
|
-
#{singular_name}: #{singular_name},
|
164
159
|
{
|
165
160
|
type: 'success',
|
166
161
|
message: I18n.t(:'flashes.#{plural_name}.update.success')
|
@@ -176,7 +171,9 @@ FILE
|
|
176
171
|
create_file "app/graphql/mutations/#{plural_name}/delete_#{singular_name}.rb", <<~FILE
|
177
172
|
module Mutations
|
178
173
|
class #{plural_name.camelcase}::Delete#{singular_name.camelcase} < BaseMutation
|
179
|
-
|
174
|
+
|
175
|
+
field :#{singular_name}, Types::#{plural_name.camelcase}::#{singular_name.camelcase}Type
|
176
|
+
field :flash_messages, [Types::JsonType], null: true
|
180
177
|
|
181
178
|
argument :id, ID, required: true
|
182
179
|
|
@@ -189,6 +186,7 @@ FILE
|
|
189
186
|
#{singular_name} = ::#{singular_name.camelcase}.find id
|
190
187
|
#{singular_name}.destroy!
|
191
188
|
{
|
189
|
+
#{singular_name}: #{singular_name},
|
192
190
|
flash_messages: [
|
193
191
|
{
|
194
192
|
type: 'success',
|
@@ -201,19 +199,62 @@ FILE
|
|
201
199
|
end
|
202
200
|
FILE
|
203
201
|
|
202
|
+
inject_into_file 'app/graphql/types/mutation_type.rb', after: "Types::BaseObject" do <<-FILE
|
203
|
+
|
204
|
+
field :create_#{singular_name}, mutation: Mutations::#{plural_name.camelcase}::Create#{singular_name.camelcase}
|
205
|
+
field :update_#{singular_name}, mutation: Mutations::#{plural_name.camelcase}::Update#{singular_name.camelcase}
|
206
|
+
field :delete_#{singular_name}, mutation: Mutations::#{plural_name.camelcase}::Delete#{singular_name.camelcase}
|
207
|
+
FILE
|
208
|
+
end
|
209
|
+
|
204
210
|
puts 'Do you want to create the payload file ? (y/n)'
|
205
211
|
input = $stdin.gets.strip
|
206
212
|
if input == 'y'
|
207
|
-
create_file "app/graphql/types/#{
|
213
|
+
create_file "app/graphql/types/#{plural_name}/#{singular_name}_list_payload.rb", <<~FILE
|
208
214
|
module Types
|
209
|
-
module #{
|
215
|
+
module #{plural_name.camelcase}
|
210
216
|
class #{singular_name.camelcase}ListPayload < BaseObject
|
211
|
-
field :#{plural_name}, [#{
|
217
|
+
field :#{plural_name}, [#{plural_name.camelcase}::#{singular_name.camelcase}Type], null: true
|
212
218
|
field :pagination, PaginationType, null: true
|
213
219
|
end
|
214
220
|
end
|
215
221
|
end
|
216
222
|
FILE
|
223
|
+
|
224
|
+
# Attributes file
|
225
|
+
create_file "app/graphql/input_object/search_#{plural_name}_attributes.rb", <<~FILE
|
226
|
+
module InputObject
|
227
|
+
class Search#{plural_name.camelcase}Attributes < AttributesInputObject
|
228
|
+
|
229
|
+
end
|
230
|
+
end
|
231
|
+
FILE
|
232
|
+
|
233
|
+
inject_into_file 'app/graphql/types/query_type.rb', after: "# Fields\n" do <<-FILE
|
234
|
+
field :#{plural_name}, Types::#{plural_name.camelcase}::#{singular_name.camelcase}ListPayload do
|
235
|
+
argument :search, InputObject::Search#{plural_name.camelcase}Attributes, required: false
|
236
|
+
argument :page, Integer, required: false
|
237
|
+
argument :per_page, Integer, required: false
|
238
|
+
end
|
239
|
+
def #{plural_name}(search: {}, page: 1, per_page: 25)
|
240
|
+
ctx = ::#{plural_name.camelcase}::Search#{singular_name.camelcase}.call(search: search, pagination_params: { page: page, per_page: per_page })
|
241
|
+
{
|
242
|
+
#{plural_name}: ctx.records,
|
243
|
+
pagination: ctx.pagination
|
244
|
+
}
|
245
|
+
end\n
|
246
|
+
FILE
|
247
|
+
end
|
248
|
+
|
249
|
+
inject_into_file 'app/graphql/types/query_type.rb', after: "# Fields\n" do <<-FILE
|
250
|
+
field :#{singular_name}, Types::#{plural_name.camelcase}::#{singular_name.camelcase}Type do
|
251
|
+
argument :id, ID, required: true
|
252
|
+
end
|
253
|
+
def #{singular_name}(id:)
|
254
|
+
::#{singular_name.camelcase}.find(id)
|
255
|
+
end\n
|
256
|
+
FILE
|
257
|
+
end
|
217
258
|
end
|
218
259
|
end
|
219
260
|
end
|
data/lib/ntq_tools/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ntq_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|