datarockets-style 1.4.0 → 1.5.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 +4 -4
- data/.github/workflows/main.yml +2 -2
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +15 -0
- data/Gemfile +1 -1
- data/README.md +12 -2
- data/config/graphql.yml +10 -0
- data/datarockets-style.gemspec +5 -4
- data/doc/STYLE_GUIDE_GRAPHQL.md +486 -0
- data/lib/datarockets_style/formatter/todo_list_formatter.rb +1 -1
- data/lib/datarockets_style/version.rb +1 -1
- metadata +25 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fae6be6c9b336722b260f0e5cfd4d650d95e5cd96e453756b5bcbbf3b74f13bd
|
|
4
|
+
data.tar.gz: 4bb202204deb99f738fad88e8b8b6aebfcb8ba1c59a4ead9a6c8ad39ab25e952
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 12f51702b7b03323daf313e476c1bb70e8daa6ffcea8d1d5c0b7ec2b01915cd31147a77c79c62b3bf876dddbe68fe221def1848c2cbb82d17242f7e1e018719e
|
|
7
|
+
data.tar.gz: e79c1b517947247f4c76f06e59e1c52816193080162b412b3f3beea3900d97d3f8b32749d99335dfadb1be51266bca04cb0cf385b515034a60def7341577ca39
|
data/.github/workflows/main.yml
CHANGED
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,20 @@ The format is described in [Contributing notes](CONTRIBUTING.md#changelog-entry-
|
|
|
4
4
|
|
|
5
5
|
## master
|
|
6
6
|
|
|
7
|
+
## 1.5.0 (2023-09-11)
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
* Added GraphQL cops. ([@Anastastasia-B][])
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
|
|
15
|
+
* **(Breaking)** Support Ruby >= 2.7.0
|
|
16
|
+
|
|
17
|
+
* Update rubocop to `1.56.3`. ([@Set27])
|
|
18
|
+
* Update rubocop-rails to `2.21.0`. ([@Set27])
|
|
19
|
+
* Update rubocop-spec to `2.24.0`. ([@Set27])
|
|
20
|
+
|
|
7
21
|
## 1.4.0 (2023-02-11)
|
|
8
22
|
|
|
9
23
|
### Changed
|
|
@@ -272,3 +286,4 @@ The format is described in [Contributing notes](CONTRIBUTING.md#changelog-entry-
|
|
|
272
286
|
[@a.branzeanu]: https://github.com/texpert
|
|
273
287
|
[@nikitasakov]: https://github.com/nikitasakov
|
|
274
288
|
[@paydaylight]: https://github.com/paydaylight
|
|
289
|
+
[@Anastastasia-B]: https://github.com/Anastastasia-B
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -10,14 +10,14 @@ Add this line to your application's Gemfile:
|
|
|
10
10
|
|
|
11
11
|
```ruby
|
|
12
12
|
group :test, :development do
|
|
13
|
-
gem 'datarockets-style', '~> 1.
|
|
13
|
+
gem 'datarockets-style', '~> 1.5.0'
|
|
14
14
|
end
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
Or, for a Ruby library, add this to your gemspec:
|
|
18
18
|
|
|
19
19
|
```ruby
|
|
20
|
-
spec.add_development_dependency 'datarockets-style', '~> 1.
|
|
20
|
+
spec.add_development_dependency 'datarockets-style', '~> 1.5.0'
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
And then execute:
|
|
@@ -60,6 +60,16 @@ inherit_gem:
|
|
|
60
60
|
- config/rails-locales.yml
|
|
61
61
|
```
|
|
62
62
|
|
|
63
|
+
### GraphQL config
|
|
64
|
+
|
|
65
|
+
To include specific rules for GraphQL, you can add the following config
|
|
66
|
+
|
|
67
|
+
```yaml
|
|
68
|
+
inherit_gem:
|
|
69
|
+
datarockets-style:
|
|
70
|
+
- config/graphql.yml
|
|
71
|
+
```
|
|
72
|
+
|
|
63
73
|
### Rspec config
|
|
64
74
|
|
|
65
75
|
For Rspec tests, you can add a special rubocop config
|
data/config/graphql.yml
ADDED
data/datarockets-style.gemspec
CHANGED
|
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
|
|
|
14
14
|
spec.homepage = "https://github.com/datarockets/datarockets-style"
|
|
15
15
|
spec.license = "MIT"
|
|
16
16
|
|
|
17
|
-
spec.required_ruby_version = ">= 2.
|
|
17
|
+
spec.required_ruby_version = ">= 2.7.0"
|
|
18
18
|
|
|
19
19
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
|
20
20
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
|
@@ -32,9 +32,10 @@ Gem::Specification.new do |spec|
|
|
|
32
32
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
33
33
|
spec.require_paths = ["lib"]
|
|
34
34
|
|
|
35
|
-
spec.add_dependency "rubocop", "~> 1.
|
|
36
|
-
spec.add_dependency "rubocop-
|
|
37
|
-
spec.add_dependency "rubocop-
|
|
35
|
+
spec.add_dependency "rubocop", "~> 1.56.3"
|
|
36
|
+
spec.add_dependency "rubocop-graphql", "~> 1.4"
|
|
37
|
+
spec.add_dependency "rubocop-rails", "~> 2.21"
|
|
38
|
+
spec.add_dependency "rubocop-rspec", "~> 2.24"
|
|
38
39
|
|
|
39
40
|
spec.metadata["rubygems_mfa_required"] = "true"
|
|
40
41
|
end
|
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
# GraphQL Style Guide
|
|
2
|
+
|
|
3
|
+
This style is based on the rules from [RuboCop::GraphQL](https://github.com/DmitryTsepelev/rubocop-graphql) gem with a few differences.
|
|
4
|
+
|
|
5
|
+
## Table of contents
|
|
6
|
+
|
|
7
|
+
* [Style](#Style)
|
|
8
|
+
|
|
9
|
+
## Style
|
|
10
|
+
|
|
11
|
+
* <a name="graphql-argument-description"></a>
|
|
12
|
+
Each argument should have a description.
|
|
13
|
+
<sup>[[link](#graphql-argument-description)]</sup>
|
|
14
|
+
|
|
15
|
+
```ruby
|
|
16
|
+
# bad
|
|
17
|
+
class BanUser < BaseMutation
|
|
18
|
+
argument :uuid, ID, required: true
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# good
|
|
22
|
+
class BanUser < BaseMutation
|
|
23
|
+
argument :uuid, ID, required: true, description: "UUID of the user to ban"
|
|
24
|
+
end
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
* <a name="graphql-argument-name"></a>
|
|
28
|
+
All argument names should be snake_case.
|
|
29
|
+
<sup>[[link](#graphql-argument-name)]</sup>
|
|
30
|
+
|
|
31
|
+
```ruby
|
|
32
|
+
# bad
|
|
33
|
+
class BanUser < BaseMutation
|
|
34
|
+
argument :userId, ID, required: true
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# good
|
|
38
|
+
class BanUser < BaseMutation
|
|
39
|
+
argument :user_id, ID, required: true
|
|
40
|
+
end
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
* <a name="graphql-argument-uniqueness"></a>
|
|
44
|
+
Avoid duplicate argument definitions.
|
|
45
|
+
<sup>[[link](#graphql-argument-uniqueness)]</sup>
|
|
46
|
+
|
|
47
|
+
```ruby
|
|
48
|
+
# bad
|
|
49
|
+
class BanUser < BaseMutation
|
|
50
|
+
argument :user_id, ID, required: true
|
|
51
|
+
argument :user_id, ID, required: true
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# good
|
|
55
|
+
class BanUser < BaseMutation
|
|
56
|
+
argument :user_id, ID, required: true
|
|
57
|
+
end
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
* <a name="graphql-field-definitions"></a>
|
|
61
|
+
All field definitions should be grouped together.
|
|
62
|
+
<sup>[[link](#graphql-field-definitions)]</sup>
|
|
63
|
+
|
|
64
|
+
```ruby
|
|
65
|
+
# bad
|
|
66
|
+
class UserType < BaseType
|
|
67
|
+
field :first_name, String, null: true
|
|
68
|
+
|
|
69
|
+
def first_name
|
|
70
|
+
object.contact_data.first_name
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
field :last_name, String, null: true
|
|
74
|
+
|
|
75
|
+
def last_name
|
|
76
|
+
object.contact_data.last_name
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# good
|
|
81
|
+
class UserType < BaseType
|
|
82
|
+
field :first_name, String, null: true
|
|
83
|
+
field :last_name, String, null: true
|
|
84
|
+
|
|
85
|
+
def first_name
|
|
86
|
+
object.contact_data.first_name
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def last_name
|
|
90
|
+
object.contact_data.last_name
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
* <a name="graphql-field-description"></a>
|
|
96
|
+
Each field should have a description.
|
|
97
|
+
<sup>[[link](#graphql-field-description)]</sup>
|
|
98
|
+
|
|
99
|
+
```ruby
|
|
100
|
+
# bad
|
|
101
|
+
class UserType < BaseType
|
|
102
|
+
field :name, String, null: true
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# good
|
|
106
|
+
class UserType < BaseType
|
|
107
|
+
field :name, String, "Name of the user", null: true
|
|
108
|
+
end
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
* <a name="graphql-field-hash-key"></a>
|
|
112
|
+
Avoid unnecessary resolver methods in cases when :hash_key option can be used.
|
|
113
|
+
<sup>[[link](#graphql-field-hash-key)]</sup>
|
|
114
|
+
|
|
115
|
+
```ruby
|
|
116
|
+
# bad
|
|
117
|
+
class Types::UserType < Types::BaseObject
|
|
118
|
+
field :phone, String, null: true
|
|
119
|
+
|
|
120
|
+
def phone
|
|
121
|
+
object[:home_phone]
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# good
|
|
126
|
+
class Types::UserType < Types::BaseObject
|
|
127
|
+
field :phone, String, null: true, hash_key: :home_phone
|
|
128
|
+
end
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
* <a name="graphql-field-mathod"></a>
|
|
132
|
+
Avoid unnecessary resolver methods in cases when :method option can be used.
|
|
133
|
+
<sup>[[link](#graphql-field-mathod)]</sup>
|
|
134
|
+
|
|
135
|
+
```ruby
|
|
136
|
+
# bad
|
|
137
|
+
class Types::UserType < Types::BaseObject
|
|
138
|
+
field :phone, String, null: true
|
|
139
|
+
|
|
140
|
+
def phone
|
|
141
|
+
object.home_phone
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# good
|
|
146
|
+
class Types::UserType < Types::BaseObject
|
|
147
|
+
field :phone, String, null: true, method: :home_phone
|
|
148
|
+
end
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
* <a name="graphql-field-name"></a>
|
|
152
|
+
All field names should be snake_case.
|
|
153
|
+
<sup>[[link](#graphql-field-name)]</sup>
|
|
154
|
+
|
|
155
|
+
```ruby
|
|
156
|
+
# bad
|
|
157
|
+
class UserType < BaseType
|
|
158
|
+
field :firstName, String, null: true
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
# good
|
|
162
|
+
class UserType < BaseType
|
|
163
|
+
field :first_name, String, null: true
|
|
164
|
+
end
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
* <a name="graphql-field-uniqueness"></a>
|
|
168
|
+
Avoid duplicate field definitions.
|
|
169
|
+
<sup>[[link](#graphql-field-uniqueness)]</sup>
|
|
170
|
+
|
|
171
|
+
```ruby
|
|
172
|
+
# bad
|
|
173
|
+
class UserType < BaseType
|
|
174
|
+
field :name, String, null: true
|
|
175
|
+
field :phone, String, null: true
|
|
176
|
+
field :phone, String, null: true do
|
|
177
|
+
argument :something, String, required: false
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
# good
|
|
182
|
+
class UserType < BaseType
|
|
183
|
+
field :name, String, null: true
|
|
184
|
+
field :phone, String, null: true do
|
|
185
|
+
argument :something, String, required: false
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
* <a name="graphql-graphql-name"></a>
|
|
191
|
+
Types and mutations should have graphql_name configured only if it's different from the default name.
|
|
192
|
+
<sup>[[link](#graphql-graphql-name)]</sup>
|
|
193
|
+
|
|
194
|
+
```ruby
|
|
195
|
+
# bad
|
|
196
|
+
class UserType < BaseType
|
|
197
|
+
graphql_name 'User'
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
# good
|
|
201
|
+
class UserType < BaseType
|
|
202
|
+
graphql_name 'Viewer'
|
|
203
|
+
end
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
* <a name="graphql-max-complexity-schema"></a>
|
|
207
|
+
Use max_complexity configuration in schema files.
|
|
208
|
+
<sup>[[link](#graphql-max-complexity-schema)]</sup>
|
|
209
|
+
|
|
210
|
+
```ruby
|
|
211
|
+
# good
|
|
212
|
+
class AppSchema < BaseSchema
|
|
213
|
+
max_complexity 42
|
|
214
|
+
end
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
* <a name="graphql-max-depth-schema"></a>
|
|
218
|
+
Use max_depth configuration in schema files.
|
|
219
|
+
<sup>[[link](#graphql-max-depth-schema)]</sup>
|
|
220
|
+
|
|
221
|
+
```ruby
|
|
222
|
+
# good
|
|
223
|
+
class AppSchema < BaseSchema
|
|
224
|
+
max_depth 42
|
|
225
|
+
end
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
* <a name="graphql-multiple-field-definitions"></a>
|
|
229
|
+
Fields with multiple definitions should be grouped together.
|
|
230
|
+
<sup>[[link](#graphql-multiple-field-definitions)]</sup>
|
|
231
|
+
|
|
232
|
+
```ruby
|
|
233
|
+
# bad
|
|
234
|
+
class UserType < BaseType
|
|
235
|
+
field :first_name, String, null: true
|
|
236
|
+
|
|
237
|
+
def first_name
|
|
238
|
+
object.contact_data.first_name
|
|
239
|
+
end
|
|
240
|
+
field :first_name, Name, null: true
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
# good
|
|
244
|
+
class UserType < BaseType
|
|
245
|
+
field :first_name, String, null: true
|
|
246
|
+
field :first_name, Name, null: true
|
|
247
|
+
|
|
248
|
+
def first_name
|
|
249
|
+
object.contact_data.first_name
|
|
250
|
+
end
|
|
251
|
+
end
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
* <a name="graphql-not-authorized-node-type"></a>
|
|
255
|
+
Types that implement Node interface should have `.authorized?` check. Such types can be fetched by ID and therefore should have type level check to avoid accidental information exposure.
|
|
256
|
+
If `.authorized?` is defined in a parent class, you can add parent to the "SafeBaseClasses" to avoid offenses in children.
|
|
257
|
+
This cop also checks the `can_can_action` or `pundit_role` methods that can be used as part of the Ruby GraphQL Pro.
|
|
258
|
+
<sup>[[link](#graphql-not-authorized-node-type)]</sup>
|
|
259
|
+
|
|
260
|
+
```ruby
|
|
261
|
+
# bad
|
|
262
|
+
class UserType < BaseType
|
|
263
|
+
implements GraphQL::Types::Relay::Node
|
|
264
|
+
|
|
265
|
+
field :uuid, ID, null: false
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
# good
|
|
269
|
+
class UserType < BaseType
|
|
270
|
+
implements GraphQL::Types::Relay::Node
|
|
271
|
+
|
|
272
|
+
field :uuid, ID, null: false
|
|
273
|
+
|
|
274
|
+
def self.authorized?(object, context)
|
|
275
|
+
super && object.owner == context[:viewer]
|
|
276
|
+
end
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
# good
|
|
280
|
+
class UserType < BaseType
|
|
281
|
+
implements GraphQL::Types::Relay::Node
|
|
282
|
+
|
|
283
|
+
pundit_role :staff
|
|
284
|
+
|
|
285
|
+
field :uuid, ID, null: false
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
# good
|
|
289
|
+
class UserType < BaseType
|
|
290
|
+
implements GraphQL::Types::Relay::Node
|
|
291
|
+
|
|
292
|
+
can_can_action :staff
|
|
293
|
+
|
|
294
|
+
field :uuid, ID, null: false
|
|
295
|
+
end
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
* <a name="graphql-object-description"></a>
|
|
299
|
+
All types (objects, inputs, interfaces, scalars, unions, mutations, subscriptions, and resolvers) should have a description.
|
|
300
|
+
<sup>[[link](#graphql-object-description)]</sup>
|
|
301
|
+
|
|
302
|
+
```ruby
|
|
303
|
+
# bad
|
|
304
|
+
class Types::UserType < Types::BaseObject
|
|
305
|
+
...
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
# good
|
|
309
|
+
class Types::UserType < Types::BaseObject
|
|
310
|
+
description "Represents application user"
|
|
311
|
+
...
|
|
312
|
+
end
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
* <a name="graphql-ordered-arguments"></a>
|
|
316
|
+
Arguments should be alphabetically sorted within groups.
|
|
317
|
+
<sup>[[link](#graphql-ordered-arguments)]</sup>
|
|
318
|
+
|
|
319
|
+
```ruby
|
|
320
|
+
# bad
|
|
321
|
+
class UpdateProfile < BaseMutation
|
|
322
|
+
argument :uuid, ID, required: true
|
|
323
|
+
argument :email, String, required: false
|
|
324
|
+
argument :name, String, required: false
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
# good
|
|
328
|
+
class UpdateProfile < BaseMutation
|
|
329
|
+
argument :email, String, required: false
|
|
330
|
+
argument :name, String, required: false
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
# good
|
|
334
|
+
class UpdateProfile < BaseMutation
|
|
335
|
+
argument :uuid, ID, required: true
|
|
336
|
+
|
|
337
|
+
argument :email, String, required: false
|
|
338
|
+
argument :name, String, required: false
|
|
339
|
+
end
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
* <a name="graphql-ordered-fields"></a>
|
|
343
|
+
Fields should be alphabetically sorted within groups.
|
|
344
|
+
<sup>[[link](#graphql-ordered-fields)]</sup>
|
|
345
|
+
|
|
346
|
+
```ruby
|
|
347
|
+
# bad
|
|
348
|
+
class UpdateProfile < BaseMutation
|
|
349
|
+
field :phone, String, null: true
|
|
350
|
+
field :name, String, null: true
|
|
351
|
+
end
|
|
352
|
+
|
|
353
|
+
# good
|
|
354
|
+
class UpdateProfile < BaseMutation
|
|
355
|
+
field :name, String, null: true
|
|
356
|
+
field :phone, String, null: true
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
# good
|
|
360
|
+
class UpdateProfile < BaseMutation
|
|
361
|
+
field :phone, String, null: true
|
|
362
|
+
|
|
363
|
+
field :name, String, null: true
|
|
364
|
+
end
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
* <a name="graphql-resolver-method-length"></a>
|
|
368
|
+
The length of a resolver method should not exceed 10 lines.
|
|
369
|
+
<sup>[[link](#graphql-resolver-method-length)]</sup>
|
|
370
|
+
|
|
371
|
+
* <a name="graphql-unnecessary-argument-camelize"></a>
|
|
372
|
+
Avoid using :camelize option for arguments where it is unnecessary.
|
|
373
|
+
<sup>[[link](#graphql-unnecessary-argument-camelize)]</sup>
|
|
374
|
+
|
|
375
|
+
```ruby
|
|
376
|
+
# bad
|
|
377
|
+
class UserType < BaseType
|
|
378
|
+
argument :filter, String, required: false, camelize: false
|
|
379
|
+
end
|
|
380
|
+
|
|
381
|
+
# good
|
|
382
|
+
class UserType < BaseType
|
|
383
|
+
argument :filter, String, required: false
|
|
384
|
+
end
|
|
385
|
+
|
|
386
|
+
# good
|
|
387
|
+
class UserType < BaseType
|
|
388
|
+
argument :email_filter, String, required: false, camelize: true
|
|
389
|
+
end
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
* <a name="graphql-unnecessary-field-alias"></a>
|
|
393
|
+
Avoid defining an unnecessary alias, method, or resolver_method.
|
|
394
|
+
<sup>[[link](#graphql-unnecessary-field-alias)]</sup>
|
|
395
|
+
|
|
396
|
+
```ruby
|
|
397
|
+
# bad
|
|
398
|
+
field :name, String, "Name of the user", null: true, alias: :name
|
|
399
|
+
field :name, String, "Name of the user", null: true, method: :name
|
|
400
|
+
field :name, String, "Name of the user", null: true, resolver_method: :name
|
|
401
|
+
field :name, String, "Name of the user", null: true, hash_key: :name
|
|
402
|
+
|
|
403
|
+
# good
|
|
404
|
+
field :name, String, "Name of the user", null: true, alias: :real_name
|
|
405
|
+
field :name, String, "Name of the user", null: true, method: :real_name
|
|
406
|
+
field :name, String, "Name of the user", null: true, resolver_method: :real_name
|
|
407
|
+
field :name, String, "Name of the user", null: true, hash_key: :real_name
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
* <a name="graphql-unnecessary-field-camelize"></a>
|
|
411
|
+
Avoid using :camelize option for fields where it is unnecessary.
|
|
412
|
+
<sup>[[link](#graphql-unnecessary-field-camelize)]</sup>
|
|
413
|
+
|
|
414
|
+
```ruby
|
|
415
|
+
# bad
|
|
416
|
+
class UserType < BaseType
|
|
417
|
+
field :name, "Name of the user", String, null: true, camelize: true
|
|
418
|
+
end
|
|
419
|
+
|
|
420
|
+
# good
|
|
421
|
+
class UserType < BaseType
|
|
422
|
+
field :name, String, "Name of the user", null: true
|
|
423
|
+
end
|
|
424
|
+
|
|
425
|
+
# good
|
|
426
|
+
class UserType < BaseType
|
|
427
|
+
field :first_name, "Name of the user", String, null: true, camelize: true
|
|
428
|
+
end
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
* <a name="graphql-unused-argument"></a>
|
|
432
|
+
Arguments should either be listed explicitly or **rest should be in the resolve signature (and similar methods, such as #authorized?).
|
|
433
|
+
<sup>[[link](#graphql-unused-argument)]</sup>
|
|
434
|
+
|
|
435
|
+
```ruby
|
|
436
|
+
# bad
|
|
437
|
+
class SomeResolver < Resolvers::Base
|
|
438
|
+
type SomeType, null: false
|
|
439
|
+
|
|
440
|
+
argument :arg1, String, required: true
|
|
441
|
+
argument :arg2, String, required: true
|
|
442
|
+
|
|
443
|
+
def authorized?; end
|
|
444
|
+
def resolve(arg1:); end
|
|
445
|
+
end
|
|
446
|
+
|
|
447
|
+
# bad
|
|
448
|
+
class SomeResolver < Resolvers::Base
|
|
449
|
+
type SomeType, null: false
|
|
450
|
+
|
|
451
|
+
argument :arg1, String, required: true
|
|
452
|
+
argument :arg2, String, required: true
|
|
453
|
+
|
|
454
|
+
def resolve; end
|
|
455
|
+
end
|
|
456
|
+
|
|
457
|
+
# good
|
|
458
|
+
class SomeResolver < Resolvers::Base
|
|
459
|
+
argument :arg1, String, required: true
|
|
460
|
+
argument :user_id, String, required: true, loads: Types::UserType
|
|
461
|
+
argument :post_id, String, loads: Types::PostType, as: :article
|
|
462
|
+
argument :comment_ids, String, loads: Types::CommentType
|
|
463
|
+
|
|
464
|
+
def authorized?(arg1:, user:, article:, comments:); end
|
|
465
|
+
def resolve(arg1:, user:, article:, comments:); end
|
|
466
|
+
end
|
|
467
|
+
|
|
468
|
+
# good
|
|
469
|
+
class SomeResolver < Resolvers::Base
|
|
470
|
+
argument :arg1, String, required: true
|
|
471
|
+
argument :user_id, String, required: true, loads: Types::UserType
|
|
472
|
+
argument :comment_ids, String, loads: Types::CommentType
|
|
473
|
+
|
|
474
|
+
def resolve(arg1:, **rest); end
|
|
475
|
+
end
|
|
476
|
+
|
|
477
|
+
# good
|
|
478
|
+
class SomeResolver < Resolvers::Base
|
|
479
|
+
type SomeType, null: false
|
|
480
|
+
|
|
481
|
+
argument :arg1, String, required: true
|
|
482
|
+
argument :arg2, String, required: true
|
|
483
|
+
|
|
484
|
+
def resolve(args); end
|
|
485
|
+
end
|
|
486
|
+
```
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "pathname"
|
|
4
|
-
require_relative "
|
|
4
|
+
require_relative "todo_list_formatter/report_summary"
|
|
5
5
|
|
|
6
6
|
# This formatter works like default formattter (display dots for files with no offenses and
|
|
7
7
|
# letters for files with problems in the them).
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: datarockets-style
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Roman Dubrovsky
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2023-
|
|
11
|
+
date: 2023-09-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rubocop
|
|
@@ -16,42 +16,56 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 1.
|
|
19
|
+
version: 1.56.3
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: 1.
|
|
26
|
+
version: 1.56.3
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rubocop-graphql
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '1.4'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.4'
|
|
27
41
|
- !ruby/object:Gem::Dependency
|
|
28
42
|
name: rubocop-rails
|
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
|
30
44
|
requirements:
|
|
31
45
|
- - "~>"
|
|
32
46
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: 2.
|
|
47
|
+
version: '2.21'
|
|
34
48
|
type: :runtime
|
|
35
49
|
prerelease: false
|
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
51
|
requirements:
|
|
38
52
|
- - "~>"
|
|
39
53
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: 2.
|
|
54
|
+
version: '2.21'
|
|
41
55
|
- !ruby/object:Gem::Dependency
|
|
42
56
|
name: rubocop-rspec
|
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
|
44
58
|
requirements:
|
|
45
59
|
- - "~>"
|
|
46
60
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: 2.
|
|
61
|
+
version: '2.24'
|
|
48
62
|
type: :runtime
|
|
49
63
|
prerelease: false
|
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
65
|
requirements:
|
|
52
66
|
- - "~>"
|
|
53
67
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: 2.
|
|
68
|
+
version: '2.24'
|
|
55
69
|
description:
|
|
56
70
|
email:
|
|
57
71
|
- r.dubrovsky@datarockets.com
|
|
@@ -78,12 +92,14 @@ files:
|
|
|
78
92
|
- bin/console
|
|
79
93
|
- bin/setup
|
|
80
94
|
- config/base.yml
|
|
95
|
+
- config/graphql.yml
|
|
81
96
|
- config/rails-locales.yml
|
|
82
97
|
- config/rails.yml
|
|
83
98
|
- config/rspec.yml
|
|
84
99
|
- config/ruby.yml
|
|
85
100
|
- datarockets-style.gemspec
|
|
86
101
|
- doc/STYLE_GUIDE.md
|
|
102
|
+
- doc/STYLE_GUIDE_GRAPHQL.md
|
|
87
103
|
- doc/STYLE_GUIDE_RAILS.md
|
|
88
104
|
- doc/STYLE_GUIDE_RSPEC.md
|
|
89
105
|
- lib/datarockets_style.rb
|
|
@@ -108,7 +124,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
108
124
|
requirements:
|
|
109
125
|
- - ">="
|
|
110
126
|
- !ruby/object:Gem::Version
|
|
111
|
-
version: 2.
|
|
127
|
+
version: 2.7.0
|
|
112
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
129
|
requirements:
|
|
114
130
|
- - ">="
|