graphql_rails 2.4.0 → 3.1.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/ruby.yml +1 -1
- data/CHANGELOG.md +23 -1
- data/Gemfile.lock +152 -127
- data/docs/components/controller.md +15 -1
- data/docs/components/decorator.md +31 -1
- data/docs/components/model.md +92 -1
- data/graphql_rails.gemspec +1 -1
- data/lib/graphql_rails/attributes/attributable.rb +6 -0
- data/lib/graphql_rails/attributes/attribute.rb +13 -8
- data/lib/graphql_rails/attributes/attribute_configurable.rb +18 -0
- data/lib/graphql_rails/attributes/input_attribute.rb +5 -0
- data/lib/graphql_rails/attributes/type_parseable.rb +2 -2
- data/lib/graphql_rails/concerns/service.rb +1 -5
- data/lib/graphql_rails/controller/action.rb +4 -4
- data/lib/graphql_rails/controller/action_hooks_runner.rb +7 -2
- data/lib/graphql_rails/controller/build_controller_action_resolver.rb +4 -15
- data/lib/graphql_rails/controller/configuration.rb +6 -1
- data/lib/graphql_rails/controller/handle_controller_error.rb +65 -0
- data/lib/graphql_rails/controller/log_controller_action.rb +1 -0
- data/lib/graphql_rails/controller/request.rb +1 -0
- data/lib/graphql_rails/controller.rb +10 -7
- data/lib/graphql_rails/decorator/relation_decorator.rb +12 -6
- data/lib/graphql_rails/decorator.rb +10 -6
- data/lib/graphql_rails/model/add_fields_to_graphql_type.rb +2 -1
- data/lib/graphql_rails/model/call_graphql_model_method.rb +16 -4
- data/lib/graphql_rails/model/configuration.rb +15 -2
- data/lib/graphql_rails/model/direct_field_resolver.rb +31 -0
- data/lib/graphql_rails/model/find_or_build_graphql_input_type.rb +8 -0
- data/lib/graphql_rails/model/find_or_build_graphql_type.rb +34 -9
- data/lib/graphql_rails/model/find_or_build_graphql_type_class.rb +5 -2
- data/lib/graphql_rails/router/route.rb +12 -2
- data/lib/graphql_rails/router/schema_builder.rb +2 -0
- data/lib/graphql_rails/router.rb +1 -1
- data/lib/graphql_rails/rspec_controller_helpers.rb +14 -2
- data/lib/graphql_rails/version.rb +1 -1
- metadata +12 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afbec95cbbadb5f167ecc59f8e21fd4e7ab4285f97a6d6bc847129c2de03fe43
|
4
|
+
data.tar.gz: dc1434040422eda6fe0dca6ba123e6ff51a37df658bcd314be834f67c97f9d66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57801abd718d1e5bac281e01a6dfa7e54bc3da9def20f479c6c028b5b8ab8e77dbc7cd2c7e6c6a1ff6ba48cfbc7e81e0b23bb6da81f40050fbc69d6ed460af3a
|
7
|
+
data.tar.gz: 23c740466516ec437da7d7a8d909958b63d3aaca75dc3c53d748f5c7c79097c8c86c801396f4ba9e95b8fd16ae5f8cbcb9f59dcf06e0f69050cfcdc1e0ddb0cc
|
data/.github/workflows/ruby.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -9,7 +9,29 @@ 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
|
-
## [
|
12
|
+
## [3.1.0](2025-05-26)
|
13
|
+
|
14
|
+
* Added: Allow passing custom decorator build strategy
|
15
|
+
* Added: Tracer support to router
|
16
|
+
* Fixed: Better handle render in controller hooks
|
17
|
+
* Fixed: Reduce memory allocations when defining attributes
|
18
|
+
* Updated: GraphQL and gems version dependencies
|
19
|
+
* Updated: Bump rexml from 3.2.8 to 3.3.9
|
20
|
+
|
21
|
+
## [3.0.0](2024-05-31)
|
22
|
+
|
23
|
+
* Added: `input.attribute.property` method which allows aliasing input parameter keys
|
24
|
+
* Added: possibility to copy attribute config using the `Attribute#same_as` method
|
25
|
+
* Fixed: do not ignore custom `max_page_size` for paginated responses
|
26
|
+
* Fixed: do not ignore custom `default_page_size` and other options for paginated responses
|
27
|
+
* Fixed: do not crash when using deeply nested input definitions
|
28
|
+
* Added: `rescue_from` support in controllers
|
29
|
+
* Added: Bumped graphql version to 2.1.7
|
30
|
+
* Added: `implements` support in models
|
31
|
+
* Added: `response.controller` and `response.action_name` methods in RSpecControllerHelpers
|
32
|
+
* Removed: stop supporting ruby < 3.0.0
|
33
|
+
|
34
|
+
## [2.4.0](2023-11-25)
|
13
35
|
|
14
36
|
* Added: `hidden_in_groups` for attributes to be able to skip attribute from certain groups
|
15
37
|
* Added: `extras` for attributes to be able to include graphql-ruby extensions
|
data/Gemfile.lock
CHANGED
@@ -1,165 +1,188 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
graphql_rails (
|
4
|
+
graphql_rails (3.0.0)
|
5
5
|
activesupport (>= 4)
|
6
|
-
graphql (
|
6
|
+
graphql (~> 2)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
actioncable (6.1.
|
12
|
-
actionpack (= 6.1.
|
13
|
-
activesupport (= 6.1.
|
11
|
+
actioncable (6.1.7.10)
|
12
|
+
actionpack (= 6.1.7.10)
|
13
|
+
activesupport (= 6.1.7.10)
|
14
14
|
nio4r (~> 2.0)
|
15
15
|
websocket-driver (>= 0.6.1)
|
16
|
-
actionmailbox (6.1.
|
17
|
-
actionpack (= 6.1.
|
18
|
-
activejob (= 6.1.
|
19
|
-
activerecord (= 6.1.
|
20
|
-
activestorage (= 6.1.
|
21
|
-
activesupport (= 6.1.
|
16
|
+
actionmailbox (6.1.7.10)
|
17
|
+
actionpack (= 6.1.7.10)
|
18
|
+
activejob (= 6.1.7.10)
|
19
|
+
activerecord (= 6.1.7.10)
|
20
|
+
activestorage (= 6.1.7.10)
|
21
|
+
activesupport (= 6.1.7.10)
|
22
22
|
mail (>= 2.7.1)
|
23
|
-
actionmailer (6.1.
|
24
|
-
actionpack (= 6.1.
|
25
|
-
actionview (= 6.1.
|
26
|
-
activejob (= 6.1.
|
27
|
-
activesupport (= 6.1.
|
23
|
+
actionmailer (6.1.7.10)
|
24
|
+
actionpack (= 6.1.7.10)
|
25
|
+
actionview (= 6.1.7.10)
|
26
|
+
activejob (= 6.1.7.10)
|
27
|
+
activesupport (= 6.1.7.10)
|
28
28
|
mail (~> 2.5, >= 2.5.4)
|
29
29
|
rails-dom-testing (~> 2.0)
|
30
|
-
actionpack (6.1.
|
31
|
-
actionview (= 6.1.
|
32
|
-
activesupport (= 6.1.
|
30
|
+
actionpack (6.1.7.10)
|
31
|
+
actionview (= 6.1.7.10)
|
32
|
+
activesupport (= 6.1.7.10)
|
33
33
|
rack (~> 2.0, >= 2.0.9)
|
34
34
|
rack-test (>= 0.6.3)
|
35
35
|
rails-dom-testing (~> 2.0)
|
36
36
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
37
|
-
actiontext (6.1.
|
38
|
-
actionpack (= 6.1.
|
39
|
-
activerecord (= 6.1.
|
40
|
-
activestorage (= 6.1.
|
41
|
-
activesupport (= 6.1.
|
37
|
+
actiontext (6.1.7.10)
|
38
|
+
actionpack (= 6.1.7.10)
|
39
|
+
activerecord (= 6.1.7.10)
|
40
|
+
activestorage (= 6.1.7.10)
|
41
|
+
activesupport (= 6.1.7.10)
|
42
42
|
nokogiri (>= 1.8.5)
|
43
|
-
actionview (6.1.
|
44
|
-
activesupport (= 6.1.
|
43
|
+
actionview (6.1.7.10)
|
44
|
+
activesupport (= 6.1.7.10)
|
45
45
|
builder (~> 3.1)
|
46
46
|
erubi (~> 1.4)
|
47
47
|
rails-dom-testing (~> 2.0)
|
48
48
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
49
|
-
activejob (6.1.
|
50
|
-
activesupport (= 6.1.
|
49
|
+
activejob (6.1.7.10)
|
50
|
+
activesupport (= 6.1.7.10)
|
51
51
|
globalid (>= 0.3.6)
|
52
|
-
activemodel (6.1.
|
53
|
-
activesupport (= 6.1.
|
54
|
-
activerecord (6.1.
|
55
|
-
activemodel (= 6.1.
|
56
|
-
activesupport (= 6.1.
|
57
|
-
activestorage (6.1.
|
58
|
-
actionpack (= 6.1.
|
59
|
-
activejob (= 6.1.
|
60
|
-
activerecord (= 6.1.
|
61
|
-
activesupport (= 6.1.
|
62
|
-
marcel (~> 1.0
|
52
|
+
activemodel (6.1.7.10)
|
53
|
+
activesupport (= 6.1.7.10)
|
54
|
+
activerecord (6.1.7.10)
|
55
|
+
activemodel (= 6.1.7.10)
|
56
|
+
activesupport (= 6.1.7.10)
|
57
|
+
activestorage (6.1.7.10)
|
58
|
+
actionpack (= 6.1.7.10)
|
59
|
+
activejob (= 6.1.7.10)
|
60
|
+
activerecord (= 6.1.7.10)
|
61
|
+
activesupport (= 6.1.7.10)
|
62
|
+
marcel (~> 1.0)
|
63
63
|
mini_mime (>= 1.1.0)
|
64
|
-
activesupport (6.1.
|
64
|
+
activesupport (6.1.7.10)
|
65
65
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
66
66
|
i18n (>= 1.6, < 2)
|
67
67
|
minitest (>= 5.1)
|
68
68
|
tzinfo (~> 2.0)
|
69
69
|
zeitwerk (~> 2.3)
|
70
|
-
ast (2.4.
|
71
|
-
|
72
|
-
|
70
|
+
ast (2.4.3)
|
71
|
+
base64 (0.2.0)
|
72
|
+
bson (5.0.2)
|
73
|
+
builder (3.3.0)
|
73
74
|
byebug (11.1.3)
|
74
75
|
codecov (0.6.0)
|
75
76
|
simplecov (>= 0.15, < 0.22)
|
76
77
|
coderay (1.1.3)
|
77
|
-
concurrent-ruby (1.
|
78
|
+
concurrent-ruby (1.3.5)
|
78
79
|
crass (1.0.6)
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
80
|
+
date (3.4.1)
|
81
|
+
diff-lcs (1.6.1)
|
82
|
+
docile (1.4.1)
|
83
|
+
erubi (1.13.1)
|
84
|
+
fiber-storage (1.0.0)
|
85
|
+
globalid (1.2.1)
|
86
|
+
activesupport (>= 6.1)
|
87
|
+
graphql (2.4.15)
|
88
|
+
base64
|
89
|
+
fiber-storage
|
90
|
+
logger
|
91
|
+
i18n (1.14.7)
|
86
92
|
concurrent-ruby (~> 1.0)
|
87
|
-
|
93
|
+
logger (1.6.6)
|
94
|
+
loofah (2.24.0)
|
88
95
|
crass (~> 1.0.2)
|
89
|
-
nokogiri (>= 1.
|
90
|
-
mail (2.
|
96
|
+
nokogiri (>= 1.12.0)
|
97
|
+
mail (2.8.1)
|
91
98
|
mini_mime (>= 0.1.1)
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
99
|
+
net-imap
|
100
|
+
net-pop
|
101
|
+
net-smtp
|
102
|
+
marcel (1.0.4)
|
103
|
+
method_source (1.1.0)
|
104
|
+
mini_mime (1.1.5)
|
105
|
+
mini_portile2 (2.8.8)
|
106
|
+
minitest (5.25.5)
|
107
|
+
mongo (2.21.0)
|
108
|
+
bson (>= 4.14.1, < 6.0.0)
|
109
|
+
mongoid (9.0.6)
|
110
|
+
activemodel (>= 5.1, < 8.1, != 7.0.0)
|
111
|
+
concurrent-ruby (>= 1.0.5, < 2.0)
|
112
|
+
mongo (>= 2.18.0, < 3.0.0)
|
113
|
+
net-imap (0.5.6)
|
114
|
+
date
|
115
|
+
net-protocol
|
116
|
+
net-pop (0.1.2)
|
117
|
+
net-protocol
|
118
|
+
net-protocol (0.2.2)
|
119
|
+
timeout
|
120
|
+
net-smtp (0.5.1)
|
121
|
+
net-protocol
|
122
|
+
nio4r (2.7.4)
|
123
|
+
nokogiri (1.18.6)
|
124
|
+
mini_portile2 (~> 2.8.2)
|
106
125
|
racc (~> 1.4)
|
107
|
-
parallel (1.
|
108
|
-
parser (3.
|
126
|
+
parallel (1.26.3)
|
127
|
+
parser (3.3.7.3)
|
109
128
|
ast (~> 2.4.1)
|
110
|
-
|
129
|
+
racc
|
130
|
+
prism (1.4.0)
|
131
|
+
pry (0.14.2)
|
111
132
|
coderay (~> 1.1)
|
112
133
|
method_source (~> 1.0)
|
113
|
-
pry-byebug (3.
|
134
|
+
pry-byebug (3.10.1)
|
114
135
|
byebug (~> 11.0)
|
115
|
-
pry (
|
116
|
-
racc (1.
|
117
|
-
rack (2.2.
|
118
|
-
rack-test (
|
119
|
-
rack (>= 1.
|
120
|
-
rails (6.1.
|
121
|
-
actioncable (= 6.1.
|
122
|
-
actionmailbox (= 6.1.
|
123
|
-
actionmailer (= 6.1.
|
124
|
-
actionpack (= 6.1.
|
125
|
-
actiontext (= 6.1.
|
126
|
-
actionview (= 6.1.
|
127
|
-
activejob (= 6.1.
|
128
|
-
activemodel (= 6.1.
|
129
|
-
activerecord (= 6.1.
|
130
|
-
activestorage (= 6.1.
|
131
|
-
activesupport (= 6.1.
|
136
|
+
pry (>= 0.13, < 0.15)
|
137
|
+
racc (1.8.1)
|
138
|
+
rack (2.2.13)
|
139
|
+
rack-test (2.2.0)
|
140
|
+
rack (>= 1.3)
|
141
|
+
rails (6.1.7.10)
|
142
|
+
actioncable (= 6.1.7.10)
|
143
|
+
actionmailbox (= 6.1.7.10)
|
144
|
+
actionmailer (= 6.1.7.10)
|
145
|
+
actionpack (= 6.1.7.10)
|
146
|
+
actiontext (= 6.1.7.10)
|
147
|
+
actionview (= 6.1.7.10)
|
148
|
+
activejob (= 6.1.7.10)
|
149
|
+
activemodel (= 6.1.7.10)
|
150
|
+
activerecord (= 6.1.7.10)
|
151
|
+
activestorage (= 6.1.7.10)
|
152
|
+
activesupport (= 6.1.7.10)
|
132
153
|
bundler (>= 1.15.0)
|
133
|
-
railties (= 6.1.
|
154
|
+
railties (= 6.1.7.10)
|
134
155
|
sprockets-rails (>= 2.0.0)
|
135
|
-
rails-dom-testing (2.0
|
136
|
-
activesupport (>=
|
156
|
+
rails-dom-testing (2.2.0)
|
157
|
+
activesupport (>= 5.0.0)
|
158
|
+
minitest
|
137
159
|
nokogiri (>= 1.6)
|
138
|
-
rails-html-sanitizer (1.
|
139
|
-
loofah (~> 2.
|
140
|
-
|
141
|
-
|
142
|
-
|
160
|
+
rails-html-sanitizer (1.6.2)
|
161
|
+
loofah (~> 2.21)
|
162
|
+
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
|
163
|
+
railties (6.1.7.10)
|
164
|
+
actionpack (= 6.1.7.10)
|
165
|
+
activesupport (= 6.1.7.10)
|
143
166
|
method_source
|
144
|
-
rake (>=
|
167
|
+
rake (>= 12.2)
|
145
168
|
thor (~> 1.0)
|
146
169
|
rainbow (3.1.1)
|
147
|
-
rake (13.
|
148
|
-
regexp_parser (2.
|
149
|
-
rexml (3.
|
150
|
-
rspec (3.
|
151
|
-
rspec-core (~> 3.
|
152
|
-
rspec-expectations (~> 3.
|
153
|
-
rspec-mocks (~> 3.
|
154
|
-
rspec-core (3.
|
155
|
-
rspec-support (~> 3.
|
156
|
-
rspec-expectations (3.
|
170
|
+
rake (13.2.1)
|
171
|
+
regexp_parser (2.10.0)
|
172
|
+
rexml (3.4.1)
|
173
|
+
rspec (3.13.0)
|
174
|
+
rspec-core (~> 3.13.0)
|
175
|
+
rspec-expectations (~> 3.13.0)
|
176
|
+
rspec-mocks (~> 3.13.0)
|
177
|
+
rspec-core (3.13.3)
|
178
|
+
rspec-support (~> 3.13.0)
|
179
|
+
rspec-expectations (3.13.3)
|
157
180
|
diff-lcs (>= 1.2.0, < 2.0)
|
158
|
-
rspec-support (~> 3.
|
159
|
-
rspec-mocks (3.
|
181
|
+
rspec-support (~> 3.13.0)
|
182
|
+
rspec-mocks (3.13.2)
|
160
183
|
diff-lcs (>= 1.2.0, < 2.0)
|
161
|
-
rspec-support (~> 3.
|
162
|
-
rspec-support (3.
|
184
|
+
rspec-support (~> 3.13.0)
|
185
|
+
rspec-support (3.13.2)
|
163
186
|
rubocop (1.5.2)
|
164
187
|
parallel (~> 1.10)
|
165
188
|
parser (>= 2.7.1.5)
|
@@ -169,37 +192,39 @@ GEM
|
|
169
192
|
rubocop-ast (>= 1.2.0, < 2.0)
|
170
193
|
ruby-progressbar (~> 1.7)
|
171
194
|
unicode-display_width (>= 1.4.0, < 2.0)
|
172
|
-
rubocop-ast (1.
|
173
|
-
parser (>= 3.
|
195
|
+
rubocop-ast (1.43.0)
|
196
|
+
parser (>= 3.3.7.2)
|
197
|
+
prism (~> 1.4)
|
174
198
|
rubocop-performance (1.10.2)
|
175
199
|
rubocop (>= 0.90.0, < 2.0)
|
176
200
|
rubocop-ast (>= 0.4.0)
|
177
201
|
rubocop-rspec (2.4.0)
|
178
202
|
rubocop (~> 1.0)
|
179
203
|
rubocop-ast (>= 1.1.0)
|
180
|
-
ruby-progressbar (1.
|
181
|
-
ruby2_keywords (0.0.5)
|
204
|
+
ruby-progressbar (1.13.0)
|
182
205
|
simplecov (0.21.2)
|
183
206
|
docile (~> 1.1)
|
184
207
|
simplecov-html (~> 0.11)
|
185
208
|
simplecov_json_formatter (~> 0.1)
|
186
|
-
simplecov-html (0.
|
187
|
-
simplecov_json_formatter (0.1.
|
188
|
-
sprockets (4.
|
209
|
+
simplecov-html (0.13.1)
|
210
|
+
simplecov_json_formatter (0.1.4)
|
211
|
+
sprockets (4.2.1)
|
189
212
|
concurrent-ruby (~> 1.0)
|
190
|
-
rack (
|
191
|
-
sprockets-rails (3.
|
192
|
-
actionpack (>=
|
193
|
-
activesupport (>=
|
213
|
+
rack (>= 2.2.4, < 4)
|
214
|
+
sprockets-rails (3.5.2)
|
215
|
+
actionpack (>= 6.1)
|
216
|
+
activesupport (>= 6.1)
|
194
217
|
sprockets (>= 3.0.0)
|
195
|
-
thor (1.2
|
196
|
-
|
218
|
+
thor (1.3.2)
|
219
|
+
timeout (0.4.3)
|
220
|
+
tzinfo (2.0.6)
|
197
221
|
concurrent-ruby (~> 1.0)
|
198
222
|
unicode-display_width (1.8.0)
|
199
|
-
websocket-driver (0.7.
|
223
|
+
websocket-driver (0.7.7)
|
224
|
+
base64
|
200
225
|
websocket-extensions (>= 0.1.0)
|
201
226
|
websocket-extensions (0.1.5)
|
202
|
-
zeitwerk (2.6.
|
227
|
+
zeitwerk (2.6.18)
|
203
228
|
|
204
229
|
PLATFORMS
|
205
230
|
ruby
|
@@ -194,7 +194,21 @@ class UsersController < GraphqlRails::Controller
|
|
194
194
|
action(:index).paginated(max_page_size: 10) # add max items limit
|
195
195
|
|
196
196
|
def index
|
197
|
-
User.all # it will render 10 users even you have more
|
197
|
+
User.all # it will render max 10 users even you have requested more
|
198
|
+
end
|
199
|
+
end
|
200
|
+
```
|
201
|
+
|
202
|
+
#### *default_page_size*
|
203
|
+
|
204
|
+
Allows to specify max items count per request
|
205
|
+
|
206
|
+
```ruby
|
207
|
+
class UsersController < GraphqlRails::Controller
|
208
|
+
action(:index).paginated(default_page_size: 5) # add default items per page size
|
209
|
+
|
210
|
+
def index
|
211
|
+
User.all # it will render 5 users even you have more
|
198
212
|
end
|
199
213
|
end
|
200
214
|
```
|
@@ -25,7 +25,7 @@ class CommentDecorator < SimpleDelegator
|
|
25
25
|
end
|
26
26
|
```
|
27
27
|
|
28
|
-
In order to decorate object with
|
28
|
+
In order to decorate object with extra arguments, simply pass them to `.decorate` method. Like this:
|
29
29
|
|
30
30
|
```ruby
|
31
31
|
CommentDecorator.decorate(comment, current_user)
|
@@ -67,3 +67,33 @@ class UsersController < GraphqlRails::Controller
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
```
|
70
|
+
|
71
|
+
## Decorating with custom method
|
72
|
+
|
73
|
+
Sometimes building decorator instance is not that straight-forward and you need to use custom build strategy. In such cases you can pass `build_with: :DESIRED_CLASS_METHOD` option:
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
class UserDecorator < SimpleDelegator
|
77
|
+
include GraphqlRails::Model
|
78
|
+
include GraphqlRails::Decorator
|
79
|
+
# ...
|
80
|
+
|
81
|
+
def self.custom_build(user)
|
82
|
+
user.admin? ? new(user, admin: true) : new(user)
|
83
|
+
end
|
84
|
+
|
85
|
+
def initialize(user, admin: false)
|
86
|
+
@user = user
|
87
|
+
@admin = admin
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
class UsersController < GraphqlRails::Controller
|
92
|
+
action(:index).paginated.returns('[UserDecorator!]!')
|
93
|
+
|
94
|
+
def index
|
95
|
+
users = User.where(active: true)
|
96
|
+
UserDecorator.decorate(user, build_with: :custom_build)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
```
|
data/docs/components/model.md
CHANGED
@@ -368,6 +368,21 @@ class User
|
|
368
368
|
end
|
369
369
|
```
|
370
370
|
|
371
|
+
### attribute.same_as
|
372
|
+
|
373
|
+
When you want to have identical attributes, you can use `Attribute#same_as` to make sure that attribute params will stay in sync:
|
374
|
+
|
375
|
+
```ruby
|
376
|
+
class User
|
377
|
+
include GraphqlRails::Model
|
378
|
+
|
379
|
+
graphql do |c|
|
380
|
+
c.attribute(:user_id).type('ID').description('User ID')
|
381
|
+
c.attribute(:person_id).same_as(c.attribute(:user_id))
|
382
|
+
end
|
383
|
+
end
|
384
|
+
```
|
385
|
+
|
371
386
|
### attribute.with
|
372
387
|
|
373
388
|
When you want to define some options dynamically, it's quite handy to use "Attribute#with" method:
|
@@ -447,6 +462,30 @@ class User
|
|
447
462
|
end
|
448
463
|
```
|
449
464
|
|
465
|
+
## implements
|
466
|
+
|
467
|
+
`implements` indicates that graphql type implements one or more interfaces:
|
468
|
+
|
469
|
+
```ruby
|
470
|
+
module UserInterface
|
471
|
+
include GraphQL::Schema::Interface
|
472
|
+
# ....
|
473
|
+
end
|
474
|
+
|
475
|
+
module AdvancedUserInterface
|
476
|
+
include GraphQL::Schema::Interface
|
477
|
+
# ...
|
478
|
+
end
|
479
|
+
|
480
|
+
class AdminUser
|
481
|
+
include GraphqlRails::Model
|
482
|
+
|
483
|
+
graphql do |c|
|
484
|
+
c.implements(UserInterface, AdvancedUserInterface)
|
485
|
+
end
|
486
|
+
end
|
487
|
+
```
|
488
|
+
|
450
489
|
## graphql_type
|
451
490
|
|
452
491
|
Sometimes it's handy to get raw graphql type. To do so you can call:
|
@@ -588,7 +627,6 @@ class User
|
|
588
627
|
end
|
589
628
|
```
|
590
629
|
|
591
|
-
|
592
630
|
#### input attribute deprecation
|
593
631
|
|
594
632
|
You can mark input attribute as deprecated with `deprecated` method:
|
@@ -618,6 +656,59 @@ class User
|
|
618
656
|
end
|
619
657
|
```
|
620
658
|
|
659
|
+
#### input attribute config copy
|
660
|
+
|
661
|
+
You can copy existing config from other attribute using `Attribute#same_as` method:
|
662
|
+
|
663
|
+
```ruby
|
664
|
+
class User
|
665
|
+
include GraphqlRails::Model
|
666
|
+
|
667
|
+
graphql.input(:create) do |c|
|
668
|
+
c.attribute(:first_name).type('String!')
|
669
|
+
c.attribute(:last_name).type('String!')
|
670
|
+
end
|
671
|
+
|
672
|
+
graphql.input(:update) do |c|
|
673
|
+
c.attribute(:id).type('ID!')
|
674
|
+
graphql.input(:contract).attributes.each_value do |attr|
|
675
|
+
c.attribute(attr.name).same_as(attr)
|
676
|
+
end
|
677
|
+
end
|
678
|
+
end
|
679
|
+
```
|
680
|
+
|
681
|
+
#### input attribute property
|
682
|
+
|
683
|
+
Sometimes it's handy to have different input attribute on graphql level and different on controller. That's when `Attribute#property` comes to the rescue:
|
684
|
+
|
685
|
+
```ruby
|
686
|
+
class Post
|
687
|
+
include GraphqlRails::Model
|
688
|
+
|
689
|
+
graphql.input do |c|
|
690
|
+
c.attribute(:author_id).type('ID').property(:user_id)
|
691
|
+
end
|
692
|
+
end
|
693
|
+
```
|
694
|
+
|
695
|
+
Then mutation such as:
|
696
|
+
|
697
|
+
```gql
|
698
|
+
mutation createPost(input: { authorId: 123 }) {
|
699
|
+
author
|
700
|
+
}
|
701
|
+
```
|
702
|
+
|
703
|
+
Will pass `user_id` instead of `authorId` in controller:
|
704
|
+
|
705
|
+
```ruby
|
706
|
+
# posts_controller.rb
|
707
|
+
def create
|
708
|
+
Post.create!(user_id: params[:input][:user_id])
|
709
|
+
end
|
710
|
+
```
|
711
|
+
|
621
712
|
## graphql_context
|
622
713
|
|
623
714
|
It's possible to access graphql_context in your model using method `graphql_context`:
|
data/graphql_rails.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
21
|
spec.require_paths = ['lib']
|
22
22
|
|
23
|
-
spec.add_dependency 'graphql', '2
|
23
|
+
spec.add_dependency 'graphql', '~> 2'
|
24
24
|
spec.add_dependency 'activesupport', '>= 4'
|
25
25
|
|
26
26
|
spec.add_development_dependency 'bundler', '~> 2'
|
@@ -8,6 +8,12 @@ module GraphqlRails
|
|
8
8
|
# contains methods which are shared between various attribute-like classes
|
9
9
|
# expects `initial_name` and `type` to be defined
|
10
10
|
module Attributable
|
11
|
+
def initialize_copy(_original)
|
12
|
+
super
|
13
|
+
@attribute_name_parser = nil
|
14
|
+
@type_parser = nil
|
15
|
+
end
|
16
|
+
|
11
17
|
def field_name
|
12
18
|
attribute_name_parser.field_name
|
13
19
|
end
|
@@ -21,18 +21,12 @@ module GraphqlRails
|
|
21
21
|
@attributes ||= {}
|
22
22
|
end
|
23
23
|
|
24
|
-
def property(new_value = NOT_SET)
|
25
|
-
return @property if new_value == NOT_SET
|
26
|
-
|
27
|
-
@property = new_value.to_s
|
28
|
-
self
|
29
|
-
end
|
30
|
-
|
31
24
|
def field_args
|
32
25
|
[
|
33
26
|
field_name,
|
34
27
|
type_parser.type_arg,
|
35
|
-
description
|
28
|
+
description,
|
29
|
+
*field_args_options
|
36
30
|
].compact
|
37
31
|
end
|
38
32
|
|
@@ -67,6 +61,17 @@ module GraphqlRails
|
|
67
61
|
def deprecation_reason_params
|
68
62
|
{ deprecation_reason: deprecation_reason }.compact
|
69
63
|
end
|
64
|
+
|
65
|
+
def field_args_options
|
66
|
+
options = { **field_args_pagination_options }
|
67
|
+
return nil if options.empty?
|
68
|
+
|
69
|
+
[options]
|
70
|
+
end
|
71
|
+
|
72
|
+
def field_args_pagination_options
|
73
|
+
pagination_options || {}
|
74
|
+
end
|
70
75
|
end
|
71
76
|
end
|
72
77
|
end
|