ntq_tools 0.3.1 → 0.4.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: c5c6201f78773fe0427ef8b4329405e9eb2d8fef626ef26cd5800a123560856c
4
- data.tar.gz: c63e87a37de15a6f5165713e4aef872cf8e7891e033b52e277c8cbfe04e9aed9
3
+ metadata.gz: 6ae778a1b16f9e589fe5d85bc0cf643d83c6c4a86ef20e5280fa3cce218a9dca
4
+ data.tar.gz: 541dd2e07470a6d6498d6ff5a106f0b05d8a83434a3038ca4add643d5d44af96
5
5
  SHA512:
6
- metadata.gz: 0ed2ae3fc896d028160cd65f652ceebe398b97ab874ae910d80c2935bec88dbd1fe2529519585e1003bed8b6e0f4614027c205b6602b02b46f037efda9a9c074
7
- data.tar.gz: 7aaa088106b37e07cbd5cb600f968485ca6dc1d6ba97563e22bf878a7551c37e66713b97e2771288399b05243d76b31deb58e2d52b25179ab183fb627150bc35
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,23 +99,15 @@ 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
- field :#{singular_name}, Types::#{singular_name.camelcase}Type, null: false
119
111
 
120
112
  argument :attributes, InputObject::#{singular_name.camelcase}Attributes, required: true
121
113
 
@@ -145,8 +137,9 @@ FILE
145
137
  create_file "app/graphql/mutations/#{plural_name}/update_#{singular_name}.rb", <<~FILE
146
138
  module Mutations
147
139
  class #{plural_name.camelcase}::Update#{singular_name.camelcase} < BaseMutation
148
- field :flash_messages, [Types::JsonType], null: false
149
- field :#{singular_name}, Types::#{singular_name.camelcase}Type, null: false
140
+
141
+ field :#{singular_name}, Types::#{plural_name.camelcase}::#{singular_name.camelcase}Type, null: false
142
+ field :flash_messages, [Types::JsonType], null: true
150
143
 
151
144
  argument :id, ID, required: true
152
145
  argument :attributes, InputObject::#{singular_name.camelcase}Attributes, required: true
@@ -178,7 +171,9 @@ FILE
178
171
  create_file "app/graphql/mutations/#{plural_name}/delete_#{singular_name}.rb", <<~FILE
179
172
  module Mutations
180
173
  class #{plural_name.camelcase}::Delete#{singular_name.camelcase} < BaseMutation
181
- field :flash_messages, [Types::JsonType], null: false
174
+
175
+ field :#{singular_name}, Types::#{plural_name.camelcase}::#{singular_name.camelcase}Type
176
+ field :flash_messages, [Types::JsonType], null: true
182
177
 
183
178
  argument :id, ID, required: true
184
179
 
@@ -191,6 +186,7 @@ FILE
191
186
  #{singular_name} = ::#{singular_name.camelcase}.find id
192
187
  #{singular_name}.destroy!
193
188
  {
189
+ #{singular_name}: #{singular_name},
194
190
  flash_messages: [
195
191
  {
196
192
  type: 'success',
@@ -203,6 +199,14 @@ FILE
203
199
  end
204
200
  FILE
205
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
+
206
210
  puts 'Do you want to create the payload file ? (y/n)'
207
211
  input = $stdin.gets.strip
208
212
  if input == 'y'
@@ -210,12 +214,47 @@ FILE
210
214
  module Types
211
215
  module #{plural_name.camelcase}
212
216
  class #{singular_name.camelcase}ListPayload < BaseObject
213
- field :#{plural_name}, [#{singular_name.camelcase}::#{singular_name.camelcase}Type], null: true
217
+ field :#{plural_name}, [#{plural_name.camelcase}::#{singular_name.camelcase}Type], null: true
214
218
  field :pagination, PaginationType, null: true
215
219
  end
216
220
  end
217
221
  end
218
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
219
258
  end
220
259
  end
221
260
  end
@@ -1,3 +1,3 @@
1
1
  module NtqTools
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
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.3.1
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-02-28 00:00:00.000000000 Z
11
+ date: 2023-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails