graphql_rails 1.2.3 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +18 -0
- data/.hound.yml +1 -1
- data/.rubocop.yml +4 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +19 -0
- data/Gemfile +3 -3
- data/Gemfile.lock +27 -25
- data/docs/README.md +1 -1
- data/docs/components/model.md +107 -13
- data/docs/other_tools/schema_dump.md +8 -8
- data/lib/graphql_rails/attributes/attributable.rb +6 -14
- data/lib/graphql_rails/attributes/attribute.rb +10 -34
- data/lib/graphql_rails/attributes/attribute_configurable.rb +45 -0
- data/lib/graphql_rails/attributes/attribute_name_parser.rb +7 -7
- data/lib/graphql_rails/attributes/input_attribute.rb +20 -14
- data/lib/graphql_rails/attributes/input_type_parser.rb +5 -7
- data/lib/graphql_rails/attributes/type_parseable.rb +55 -19
- data/lib/graphql_rails/attributes/type_parser.rb +4 -9
- data/lib/graphql_rails/concerns/chainable_options.rb +49 -0
- data/lib/graphql_rails/controller/build_controller_action_resolver/controller_action_resolver.rb +3 -0
- data/lib/graphql_rails/decorator/relation_decorator.rb +2 -2
- data/lib/graphql_rails/input_configurable.rb +10 -8
- data/lib/graphql_rails/model/build_graphql_input_type.rb +4 -2
- data/lib/graphql_rails/model/configurable.rb +30 -8
- data/lib/graphql_rails/model/configuration.rb +26 -12
- data/lib/graphql_rails/model/find_or_build_graphql_type.rb +23 -21
- data/lib/graphql_rails/model/find_or_build_graphql_type_class.rb +2 -1
- data/lib/graphql_rails/model/input.rb +10 -26
- data/lib/graphql_rails/model.rb +1 -1
- data/lib/graphql_rails/query_runner.rb +9 -3
- data/lib/graphql_rails/router/route.rb +2 -2
- data/lib/graphql_rails/tasks/dump_graphql_schema.rb +18 -27
- data/lib/graphql_rails/tasks/dump_graphql_schemas.rb +57 -0
- data/lib/graphql_rails/tasks/schema.rake +8 -5
- data/lib/graphql_rails/types/argument_type.rb +12 -0
- data/lib/graphql_rails/types/field_type.rb +14 -0
- data/lib/graphql_rails/types/hidable_by_group.rb +32 -0
- data/lib/graphql_rails/types/object_type.rb +12 -0
- data/lib/graphql_rails/version.rb +1 -1
- metadata +15 -8
- data/.travis.yml +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd5007444af16b72661bd4c9ad03866017b9fbbaadbd4a4bccc5c788c73f95bf
|
4
|
+
data.tar.gz: 884390854d3490c9b323f82c527b922a087a0617a1a862fb5cbcd3d18f31e955
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcc498d22901bfecb649f44b266634ed762d119d0c4d876df04fbe5ae595173e61c3fe53078ea1803000fd5ec6faaa8686e1198aa2037ae6f09b91bf4e20b001
|
7
|
+
data.tar.gz: 58a8ae501e143744082ca85ac0dba51bdcf5883fa949b25d23fd4c5510c28b877c4f5ca9cbc7f0af5d6d19b7c742fa835fa4b6d7afc1ccaaca0b83c153e9aeb9
|
@@ -0,0 +1,18 @@
|
|
1
|
+
name: Ruby
|
2
|
+
on: [push, pull_request]
|
3
|
+
jobs:
|
4
|
+
specs:
|
5
|
+
strategy:
|
6
|
+
matrix:
|
7
|
+
ruby-version: ['2.6', '2.7', '3.0']
|
8
|
+
|
9
|
+
runs-on: ubuntu-latest
|
10
|
+
env:
|
11
|
+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v2
|
14
|
+
- uses: ruby/setup-ruby@v1
|
15
|
+
with:
|
16
|
+
ruby-version: ${{ matrix.ruby-version }}
|
17
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
18
|
+
- run: bundle exec rake
|
data/.hound.yml
CHANGED
data/.rubocop.yml
CHANGED
@@ -3,6 +3,9 @@ require: rubocop-rspec
|
|
3
3
|
RSpec/NestedGroups:
|
4
4
|
Enabled: false
|
5
5
|
|
6
|
+
RSpec/MultipleMemoizedHelpers:
|
7
|
+
Enabled: false
|
8
|
+
|
6
9
|
Layout/LineLength:
|
7
10
|
Enabled: true
|
8
11
|
Max: 120
|
@@ -35,6 +38,7 @@ Style/ClassAndModuleChildren:
|
|
35
38
|
- spec/**/*_spec.rb
|
36
39
|
|
37
40
|
AllCops:
|
41
|
+
NewCops: disable # TODO: enable
|
38
42
|
TargetRubyVersion: 2.7
|
39
43
|
Exclude:
|
40
44
|
- bin/*
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.0.1
|
data/CHANGELOG.md
CHANGED
@@ -9,6 +9,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
9
9
|
|
10
10
|
* Added/Changed/Deprecated/Removed/Fixed/Security: YOUR CHANGE HERE
|
11
11
|
|
12
|
+
## [2.1.0](2022-01-12)
|
13
|
+
|
14
|
+
* Added: decorated relations now can be called using "find", "empty?" and "find_by" methods
|
15
|
+
* Fixed: allow to define graphql-ruby enum classes as strings.
|
16
|
+
* Added: add "groups" to attributes.
|
17
|
+
* Changed: `date` type is now alias for `GraphQL::Types::ISO8601Date`, also added aliases for other common graphql-graphql types.
|
18
|
+
|
19
|
+
## [2.0.0](2021-12-03)
|
20
|
+
|
21
|
+
* Added: support for generating multiple schema dumps with `rake graphql_rails:schema:dump`.
|
22
|
+
* Added: support for using chainable syntax for input attributes.
|
23
|
+
* Changed: changed default `predicate method type from `Boolean` to `Boolean!`
|
24
|
+
* Changed: changed error message when trying to paginate not supported types
|
25
|
+
* Added: support defining graphql-ruby types as strings.
|
26
|
+
|
27
|
+
## [1.2.4](2021-05-05)
|
28
|
+
|
29
|
+
* Fixed: Dynamic types definition where type A references type B referencing type A.
|
30
|
+
|
12
31
|
## [1.2.3](2021-04-12)
|
13
32
|
|
14
33
|
* Fixed: Total count on paginated resources
|
data/Gemfile
CHANGED
@@ -5,9 +5,9 @@ source 'https://rubygems.org'
|
|
5
5
|
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
6
6
|
|
7
7
|
group :development do
|
8
|
-
gem 'rubocop', '
|
9
|
-
gem 'rubocop-performance'
|
10
|
-
gem 'rubocop-rspec'
|
8
|
+
gem 'rubocop', '1.5.2'
|
9
|
+
gem 'rubocop-performance'
|
10
|
+
gem 'rubocop-rspec'
|
11
11
|
end
|
12
12
|
|
13
13
|
group :test do
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
graphql_rails (1.
|
4
|
+
graphql_rails (2.1.0)
|
5
5
|
activesupport (>= 4)
|
6
6
|
graphql (~> 1.12, >= 1.12.4)
|
7
7
|
|
@@ -63,7 +63,7 @@ GEM
|
|
63
63
|
minitest (~> 5.1)
|
64
64
|
tzinfo (~> 1.1)
|
65
65
|
zeitwerk (~> 2.2, >= 2.2.2)
|
66
|
-
ast (2.4.
|
66
|
+
ast (2.4.2)
|
67
67
|
bson (4.11.0)
|
68
68
|
builder (3.2.4)
|
69
69
|
byebug (11.1.3)
|
@@ -78,7 +78,7 @@ GEM
|
|
78
78
|
erubi (1.9.0)
|
79
79
|
globalid (0.4.2)
|
80
80
|
activesupport (>= 4.2.0)
|
81
|
-
graphql (1.
|
81
|
+
graphql (1.13.4)
|
82
82
|
i18n (1.8.5)
|
83
83
|
concurrent-ruby (~> 1.0)
|
84
84
|
json (2.3.1)
|
@@ -90,9 +90,11 @@ GEM
|
|
90
90
|
marcel (0.3.3)
|
91
91
|
mimemagic (~> 0.3.2)
|
92
92
|
method_source (1.0.0)
|
93
|
-
mimemagic (0.3.
|
93
|
+
mimemagic (0.3.10)
|
94
|
+
nokogiri (~> 1)
|
95
|
+
rake
|
94
96
|
mini_mime (1.0.2)
|
95
|
-
mini_portile2 (2.
|
97
|
+
mini_portile2 (2.6.1)
|
96
98
|
minitest (5.14.2)
|
97
99
|
mongo (2.13.1)
|
98
100
|
bson (>= 4.8.2, < 5.0.0)
|
@@ -100,11 +102,11 @@ GEM
|
|
100
102
|
activemodel (>= 5.1, < 6.1)
|
101
103
|
mongo (>= 2.7.0, < 3.0.0)
|
102
104
|
nio4r (2.5.4)
|
103
|
-
nokogiri (1.
|
104
|
-
mini_portile2 (~> 2.
|
105
|
+
nokogiri (1.12.5)
|
106
|
+
mini_portile2 (~> 2.6.1)
|
105
107
|
racc (~> 1.4)
|
106
|
-
parallel (1.
|
107
|
-
parser (
|
108
|
+
parallel (1.20.1)
|
109
|
+
parser (3.0.1.1)
|
108
110
|
ast (~> 2.4.1)
|
109
111
|
pry (0.13.1)
|
110
112
|
coderay (~> 1.1)
|
@@ -144,8 +146,8 @@ GEM
|
|
144
146
|
thor (>= 0.20.3, < 2.0)
|
145
147
|
rainbow (3.0.0)
|
146
148
|
rake (13.0.1)
|
147
|
-
regexp_parser (1.
|
148
|
-
rexml (3.2.
|
149
|
+
regexp_parser (2.1.1)
|
150
|
+
rexml (3.2.5)
|
149
151
|
rspec (3.10.0)
|
150
152
|
rspec-core (~> 3.10.0)
|
151
153
|
rspec-expectations (~> 3.10.0)
|
@@ -159,24 +161,24 @@ GEM
|
|
159
161
|
diff-lcs (>= 1.2.0, < 2.0)
|
160
162
|
rspec-support (~> 3.10.0)
|
161
163
|
rspec-support (3.10.0)
|
162
|
-
rubocop (
|
164
|
+
rubocop (1.5.2)
|
163
165
|
parallel (~> 1.10)
|
164
|
-
parser (>= 2.7.1.
|
166
|
+
parser (>= 2.7.1.5)
|
165
167
|
rainbow (>= 2.2.2, < 4.0)
|
166
|
-
regexp_parser (>= 1.
|
168
|
+
regexp_parser (>= 1.8, < 3.0)
|
167
169
|
rexml
|
168
|
-
rubocop-ast (>=
|
170
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
169
171
|
ruby-progressbar (~> 1.7)
|
170
172
|
unicode-display_width (>= 1.4.0, < 2.0)
|
171
|
-
rubocop-ast (
|
172
|
-
parser (>=
|
173
|
+
rubocop-ast (1.5.0)
|
174
|
+
parser (>= 3.0.1.1)
|
173
175
|
rubocop-performance (1.8.1)
|
174
176
|
rubocop (>= 0.87.0)
|
175
177
|
rubocop-ast (>= 0.4.0)
|
176
|
-
rubocop-rspec (
|
177
|
-
rubocop (~> 0
|
178
|
-
rubocop-ast (>=
|
179
|
-
ruby-progressbar (1.
|
178
|
+
rubocop-rspec (2.3.0)
|
179
|
+
rubocop (~> 1.0)
|
180
|
+
rubocop-ast (>= 1.1.0)
|
181
|
+
ruby-progressbar (1.11.0)
|
180
182
|
simplecov (0.19.1)
|
181
183
|
docile (~> 1.1)
|
182
184
|
simplecov-html (~> 0.11)
|
@@ -211,10 +213,10 @@ DEPENDENCIES
|
|
211
213
|
rails (~> 6)
|
212
214
|
rake (~> 13.0)
|
213
215
|
rspec (~> 3.0)
|
214
|
-
rubocop (=
|
215
|
-
rubocop-performance
|
216
|
-
rubocop-rspec
|
216
|
+
rubocop (= 1.5.2)
|
217
|
+
rubocop-performance
|
218
|
+
rubocop-rspec
|
217
219
|
simplecov
|
218
220
|
|
219
221
|
BUNDLED WITH
|
220
|
-
2.
|
222
|
+
2.2.28
|
data/docs/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# GraphqlRails
|
2
2
|
|
3
|
-
|
3
|
+
![Build Status](https://github.com/samesystem/graphql_rails/workflows/Ruby/badge.svg?branch=master)
|
4
4
|
[![codecov](https://codecov.io/gh/samesystem/graphql_rails/branch/master/graph/badge.svg)](https://codecov.io/gh/samesystem/graphql_rails)
|
5
5
|
[![Documentation](https://readthedocs.org/projects/ansicolortags/badge/?version=latest)](https://samesystem.github.io/graphql_rails)
|
6
6
|
|
data/docs/components/model.md
CHANGED
@@ -27,33 +27,54 @@ Most commonly you will use `attribute` to make your model methods and attributes
|
|
27
27
|
|
28
28
|
Some types can be determined by attribute name, so you can skip this attribute:
|
29
29
|
|
30
|
-
* attributes which ends with name `*_id` has `ID
|
31
|
-
* attributes which ends with `?` has `Boolean
|
30
|
+
* attributes which ends with name `*_id` has `ID!` type
|
31
|
+
* attributes which ends with `?` has `Boolean!` type
|
32
32
|
* all other attributes without type are considered to be `String`
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
* ID: `'id'`
|
37
|
-
* String: `'string'`, `'str'`, `'text'`
|
38
|
-
* Boolean: `'bool'`, `'boolean'`
|
39
|
-
* Float: `'float'`, `'double'`, `'decimal'`
|
40
|
-
|
41
|
-
usage example:
|
34
|
+
Usage example:
|
42
35
|
|
43
36
|
```ruby
|
44
37
|
class User
|
45
38
|
include GraphqlRails::Model
|
46
39
|
|
47
40
|
graphql do |c|
|
48
|
-
c.attribute :shop_id # ID type
|
41
|
+
c.attribute :shop_id # ID! type
|
49
42
|
c.attribute :full_name # String type
|
50
|
-
c.attribute :admin? # Boolean type
|
43
|
+
c.attribute :admin? # Boolean! type
|
51
44
|
c.attribute :level, type: 'integer'
|
52
45
|
c.attribute :money, type: 'float'
|
53
46
|
end
|
54
47
|
end
|
55
48
|
```
|
56
49
|
|
50
|
+
You can also use some build in aliases for types, such as:
|
51
|
+
|
52
|
+
* `'id'` is alias for `GraphQL::Types::ID`
|
53
|
+
* `'integer'`, `'int'` are aliases for `GraphQL::Types::Int`
|
54
|
+
* `'bigint'`, `'big_int'` are aliases for `GraphQL::Types::BigInt`
|
55
|
+
* 'float', 'double', 'decimal' are aliases for `GraphQL::Types::Float`
|
56
|
+
* `'bool'`, `'boolean'` are aliases for GraphQL::Types::Boolean
|
57
|
+
* String: `'string'`, `'str'`, `'text'`
|
58
|
+
* 'date' is alias for `GraphQL::Types::ISO8601Date`
|
59
|
+
* 'time', 'datetime', 'date_time' are aliases for `GraphQL::Types::ISO8601DateTime`
|
60
|
+
* 'json' is alias for `GraphQL::Types::JSON`
|
61
|
+
|
62
|
+
Usage example:
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
class User
|
66
|
+
include GraphqlRails::Model
|
67
|
+
|
68
|
+
graphql do |c|
|
69
|
+
c.attribute(:about_me).type(:text)
|
70
|
+
c.attribute(:active).type('bool!')
|
71
|
+
c.attribute(:created_at).type(:datetime!)
|
72
|
+
c.attribute(:data).type(:json!)
|
73
|
+
c.attribute(:login_dates).type('[date!]!')
|
74
|
+
end
|
75
|
+
end
|
76
|
+
```
|
77
|
+
|
57
78
|
#### attribute.type: using graphql-ruby objects
|
58
79
|
|
59
80
|
You can also use raw graphql-ruby objects as attribute types. Here is an example:
|
@@ -72,7 +93,7 @@ end
|
|
72
93
|
class User
|
73
94
|
include GraphqlRails::Model
|
74
95
|
|
75
|
-
graphql.attribute :address, type: AddressType, required: true
|
96
|
+
graphql.attribute :address, type: 'AddressType!', required: true
|
76
97
|
end
|
77
98
|
```
|
78
99
|
|
@@ -110,6 +131,45 @@ class User
|
|
110
131
|
end
|
111
132
|
```
|
112
133
|
|
134
|
+
### attribute.groups
|
135
|
+
|
136
|
+
Groups are handy feature when you want to have multiple schemas. For example, you want to have public graphql endpoint and internal graphql endpoint where each group has some unique nodes. If attribute has `groups` set, then this attribute will be visible only in appropriate group schemas.
|
137
|
+
|
138
|
+
```ruby
|
139
|
+
class User
|
140
|
+
include GraphqlRails::Model
|
141
|
+
|
142
|
+
graphql do |c|
|
143
|
+
# visible in all schemas (default):
|
144
|
+
c.attribute(:email)
|
145
|
+
|
146
|
+
# visible in "internal" and "beta" schemas only:
|
147
|
+
c.attribute(:admin_id).groups(%i[internal beta])
|
148
|
+
|
149
|
+
# visible in "external" schema only:
|
150
|
+
c.attribute(:nickname).groups(%i[external])
|
151
|
+
end
|
152
|
+
end
|
153
|
+
```
|
154
|
+
|
155
|
+
### attribute.group
|
156
|
+
|
157
|
+
Alias for Attribute#groups.
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
class User
|
161
|
+
include GraphqlRails::Model
|
162
|
+
|
163
|
+
graphql do |c|
|
164
|
+
# visible in all schemas (default):
|
165
|
+
c.attribute(:email)
|
166
|
+
|
167
|
+
# visible in "external" schema only:
|
168
|
+
c.attribute(:nickname).group(:external)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
```
|
172
|
+
|
113
173
|
### attribute.options
|
114
174
|
|
115
175
|
Allows passing options to attribute definition. Available options:
|
@@ -243,6 +303,24 @@ class User
|
|
243
303
|
end
|
244
304
|
```
|
245
305
|
|
306
|
+
### attribute.with
|
307
|
+
|
308
|
+
When you want to define some options dynamically, it's quite handy to use "Attribute#with" method:
|
309
|
+
|
310
|
+
```ruby
|
311
|
+
class User
|
312
|
+
include GraphqlRails::Model
|
313
|
+
|
314
|
+
graphql do |c|
|
315
|
+
c.attribute(:shop_id).with(type: 'ID', description: 'references to shop')
|
316
|
+
# same as:
|
317
|
+
# c.attribute(:shop_id, type: 'ID', description: 'references to shop')
|
318
|
+
# also same as:
|
319
|
+
# c.attribute(:shop_id).type('ID').description('references to shop')
|
320
|
+
end
|
321
|
+
end
|
322
|
+
```
|
323
|
+
|
246
324
|
### "attribute" configuration with chainable methods
|
247
325
|
|
248
326
|
If your attribute definition is complex, you can define attribute in more eye-friendly chainable way with:
|
@@ -361,6 +439,22 @@ class User
|
|
361
439
|
end
|
362
440
|
```
|
363
441
|
|
442
|
+
### "input.attribute" configuration with chainable methods
|
443
|
+
|
444
|
+
If your input attribute definition is complex, you can define attribute in more eye-friendly chainable way with:
|
445
|
+
|
446
|
+
```ruby
|
447
|
+
class User
|
448
|
+
include GraphqlRails::Model
|
449
|
+
|
450
|
+
graphql.input do |c|
|
451
|
+
c.attribute(:friends_count)
|
452
|
+
.type(:integer!)
|
453
|
+
.description('Can not be zero or less')
|
454
|
+
end
|
455
|
+
end
|
456
|
+
```
|
457
|
+
|
364
458
|
#### required type
|
365
459
|
|
366
460
|
There are few ways how to mark field as required.
|
@@ -6,24 +6,24 @@ GraphqlRails includes rake task to allow creating schema snapshots easier:
|
|
6
6
|
rake graphql_rails:schema:dump
|
7
7
|
```
|
8
8
|
|
9
|
-
## Dumping
|
9
|
+
## Dumping only selected schema groups
|
10
10
|
|
11
|
-
You can
|
11
|
+
You can specify which schema groups you want to dump. In order to do so, provide groups list as rake task argument and separate group names by comma:
|
12
12
|
|
13
13
|
```bash
|
14
|
-
rake graphql_rails:schema:dump['your_group_name']
|
14
|
+
rake graphql_rails:schema:dump['your_group_name, your_group_name2']
|
15
15
|
```
|
16
16
|
|
17
|
-
|
17
|
+
You can do this also by using ENV variable `SCHEMA_GROUP_NAME`:
|
18
18
|
|
19
19
|
```bash
|
20
|
-
SCHEMA_GROUP_NAME=your_group_name rake graphql_rails:schema:dump
|
20
|
+
SCHEMA_GROUP_NAME="your_group_name, your_group_name2" rake graphql_rails:schema:dump
|
21
21
|
```
|
22
22
|
|
23
|
-
## Dumping schema in to non default
|
23
|
+
## Dumping schema in to non default folder
|
24
24
|
|
25
|
-
By default schema will be dumped to `spec/fixtures
|
25
|
+
By default schema will be dumped to `spec/fixtures` directory. If you want different schema path, add `GRAPHQL_SCHEMA_DUMP_DIR` env variable, like this:
|
26
26
|
|
27
27
|
```bash
|
28
|
-
|
28
|
+
GRAPHQL_SCHEMA_DUMP_DIR='path/to/graphql/dumps' rake graphql_rails:schema:dump
|
29
29
|
```
|
@@ -6,14 +6,14 @@ require 'graphql_rails/attributes/attribute_name_parser'
|
|
6
6
|
module GraphqlRails
|
7
7
|
module Attributes
|
8
8
|
# contains methods which are shared between various attribute-like classes
|
9
|
-
# expects `initial_name` and `
|
9
|
+
# expects `initial_name` and `type` to be defined
|
10
10
|
module Attributable
|
11
11
|
def field_name
|
12
12
|
attribute_name_parser.field_name
|
13
13
|
end
|
14
14
|
|
15
15
|
def type_name
|
16
|
-
|
16
|
+
type.to_s
|
17
17
|
end
|
18
18
|
|
19
19
|
def name
|
@@ -23,17 +23,9 @@ module GraphqlRails
|
|
23
23
|
def required?
|
24
24
|
return @required unless @required.nil?
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
def required
|
30
|
-
@required = true
|
31
|
-
self
|
32
|
-
end
|
33
|
-
|
34
|
-
def optional
|
35
|
-
@required = false
|
36
|
-
self
|
26
|
+
(type.nil? && attribute_name_parser.required?) ||
|
27
|
+
type.to_s[/!$/].present? ||
|
28
|
+
type.is_a?(GraphQL::Schema::NonNull)
|
37
29
|
end
|
38
30
|
|
39
31
|
def graphql_model
|
@@ -52,7 +44,7 @@ module GraphqlRails
|
|
52
44
|
|
53
45
|
def type_parser
|
54
46
|
@type_parser ||= begin
|
55
|
-
type_for_parser =
|
47
|
+
type_for_parser = type || attribute_name_parser.graphql_type
|
56
48
|
TypeParser.new(type_for_parser, paginated: paginated?)
|
57
49
|
end
|
58
50
|
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'graphql'
|
4
4
|
require 'graphql_rails/attributes/attributable'
|
5
|
+
require 'graphql_rails/attributes/attribute_configurable'
|
5
6
|
require 'graphql_rails/input_configurable'
|
6
7
|
|
7
8
|
module GraphqlRails
|
@@ -9,47 +10,21 @@ module GraphqlRails
|
|
9
10
|
# contains info about single graphql attribute
|
10
11
|
class Attribute
|
11
12
|
include Attributable
|
13
|
+
include AttributeConfigurable
|
12
14
|
include InputConfigurable
|
13
15
|
|
14
16
|
attr_reader :attributes
|
15
17
|
|
16
|
-
|
17
|
-
def initialize(name, type = nil, description: nil, property: name, required: nil, options: {})
|
18
|
-
@initial_type = type
|
18
|
+
def initialize(name)
|
19
19
|
@initial_name = name
|
20
|
-
@
|
21
|
-
@description = description
|
22
|
-
@property = property.to_s
|
23
|
-
@required = required
|
20
|
+
@property = name.to_s
|
24
21
|
@attributes ||= {}
|
25
22
|
end
|
26
|
-
# rubocop:enable Metrics/ParameterLists
|
27
23
|
|
28
|
-
def
|
29
|
-
return @
|
24
|
+
def property(new_value = NOT_SET)
|
25
|
+
return @property if new_value == NOT_SET
|
30
26
|
|
31
|
-
@
|
32
|
-
self
|
33
|
-
end
|
34
|
-
|
35
|
-
def description(new_description = nil)
|
36
|
-
return @description if new_description.nil?
|
37
|
-
|
38
|
-
@description = new_description
|
39
|
-
self
|
40
|
-
end
|
41
|
-
|
42
|
-
def property(new_property = nil)
|
43
|
-
return @property if new_property.nil?
|
44
|
-
|
45
|
-
@property = new_property.to_s
|
46
|
-
self
|
47
|
-
end
|
48
|
-
|
49
|
-
def options(new_options = {})
|
50
|
-
return @options if new_options.blank?
|
51
|
-
|
52
|
-
@options = new_options
|
27
|
+
@property = new_value.to_s
|
53
28
|
self
|
54
29
|
end
|
55
30
|
|
@@ -65,7 +40,8 @@ module GraphqlRails
|
|
65
40
|
{
|
66
41
|
method: property.to_sym,
|
67
42
|
null: optional?,
|
68
|
-
camelize: camelize
|
43
|
+
camelize: camelize?,
|
44
|
+
groups: groups
|
69
45
|
}
|
70
46
|
end
|
71
47
|
|
@@ -82,7 +58,7 @@ module GraphqlRails
|
|
82
58
|
|
83
59
|
protected
|
84
60
|
|
85
|
-
attr_reader :
|
61
|
+
attr_reader :initial_name
|
86
62
|
|
87
63
|
private
|
88
64
|
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'graphql_rails/attributes/type_parser'
|
4
|
+
require 'graphql_rails/attributes/attribute_name_parser'
|
5
|
+
require 'graphql_rails/model/build_enum_type'
|
6
|
+
require 'graphql_rails/concerns/chainable_options'
|
7
|
+
require 'active_support/concern'
|
8
|
+
|
9
|
+
module GraphqlRails
|
10
|
+
module Attributes
|
11
|
+
# Allows to set or get various attribute parameters
|
12
|
+
module AttributeConfigurable
|
13
|
+
extend ActiveSupport::Concern
|
14
|
+
|
15
|
+
included do
|
16
|
+
include GraphqlRails::ChainableOptions
|
17
|
+
|
18
|
+
chainable_option :description
|
19
|
+
chainable_option :options, default: {}
|
20
|
+
chainable_option :type
|
21
|
+
end
|
22
|
+
|
23
|
+
def groups(new_groups = ChainableOptions::NOT_SET)
|
24
|
+
@groups ||= []
|
25
|
+
return @groups if new_groups == ChainableOptions::NOT_SET
|
26
|
+
|
27
|
+
@groups = Array(new_groups).map(&:to_s)
|
28
|
+
self
|
29
|
+
end
|
30
|
+
|
31
|
+
def group(*args)
|
32
|
+
groups(*args)
|
33
|
+
end
|
34
|
+
|
35
|
+
def required(new_value = true) # rubocop:disable Style/OptionalBooleanParameter
|
36
|
+
@required = new_value
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
def optional(new_value = true) # rubocop:disable Style/OptionalBooleanParameter
|
41
|
+
required(!new_value)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -5,12 +5,8 @@ module GraphqlRails
|
|
5
5
|
# Parses attribute name and can generates graphql scalar type,
|
6
6
|
# grapqhl name and etc. based on that
|
7
7
|
class AttributeNameParser
|
8
|
-
attr_reader :name
|
9
|
-
|
10
8
|
def initialize(original_name, options: {})
|
11
|
-
|
12
|
-
@required = !name['!'].nil?
|
13
|
-
@name = name.tr('!', '')
|
9
|
+
@original_name = original_name.to_s
|
14
10
|
@options = options
|
15
11
|
end
|
16
12
|
|
@@ -36,12 +32,16 @@ module GraphqlRails
|
|
36
32
|
end
|
37
33
|
|
38
34
|
def required?
|
39
|
-
|
35
|
+
original_name['!'].present? || original_name.end_with?('?')
|
36
|
+
end
|
37
|
+
|
38
|
+
def name
|
39
|
+
@name ||= original_name.tr('!', '')
|
40
40
|
end
|
41
41
|
|
42
42
|
private
|
43
43
|
|
44
|
-
attr_reader :options
|
44
|
+
attr_reader :options, :original_name
|
45
45
|
|
46
46
|
def original_format?
|
47
47
|
options[:input_format] == :original || options[:attribute_name_format] == :original
|