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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +1 -1
  3. data/CHANGELOG.md +23 -1
  4. data/Gemfile.lock +152 -127
  5. data/docs/components/controller.md +15 -1
  6. data/docs/components/decorator.md +31 -1
  7. data/docs/components/model.md +92 -1
  8. data/graphql_rails.gemspec +1 -1
  9. data/lib/graphql_rails/attributes/attributable.rb +6 -0
  10. data/lib/graphql_rails/attributes/attribute.rb +13 -8
  11. data/lib/graphql_rails/attributes/attribute_configurable.rb +18 -0
  12. data/lib/graphql_rails/attributes/input_attribute.rb +5 -0
  13. data/lib/graphql_rails/attributes/type_parseable.rb +2 -2
  14. data/lib/graphql_rails/concerns/service.rb +1 -5
  15. data/lib/graphql_rails/controller/action.rb +4 -4
  16. data/lib/graphql_rails/controller/action_hooks_runner.rb +7 -2
  17. data/lib/graphql_rails/controller/build_controller_action_resolver.rb +4 -15
  18. data/lib/graphql_rails/controller/configuration.rb +6 -1
  19. data/lib/graphql_rails/controller/handle_controller_error.rb +65 -0
  20. data/lib/graphql_rails/controller/log_controller_action.rb +1 -0
  21. data/lib/graphql_rails/controller/request.rb +1 -0
  22. data/lib/graphql_rails/controller.rb +10 -7
  23. data/lib/graphql_rails/decorator/relation_decorator.rb +12 -6
  24. data/lib/graphql_rails/decorator.rb +10 -6
  25. data/lib/graphql_rails/model/add_fields_to_graphql_type.rb +2 -1
  26. data/lib/graphql_rails/model/call_graphql_model_method.rb +16 -4
  27. data/lib/graphql_rails/model/configuration.rb +15 -2
  28. data/lib/graphql_rails/model/direct_field_resolver.rb +31 -0
  29. data/lib/graphql_rails/model/find_or_build_graphql_input_type.rb +8 -0
  30. data/lib/graphql_rails/model/find_or_build_graphql_type.rb +34 -9
  31. data/lib/graphql_rails/model/find_or_build_graphql_type_class.rb +5 -2
  32. data/lib/graphql_rails/router/route.rb +12 -2
  33. data/lib/graphql_rails/router/schema_builder.rb +2 -0
  34. data/lib/graphql_rails/router.rb +1 -1
  35. data/lib/graphql_rails/rspec_controller_helpers.rb +14 -2
  36. data/lib/graphql_rails/version.rb +1 -1
  37. metadata +12 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9ef0115ce3d9107ee48ec4e7a725baff242ce81133be4a955d0a81619b106192
4
- data.tar.gz: dcb027f23eb5f6cd71b3144e2794822ee899796a5e40f7b240ea3cd59ef586b9
3
+ metadata.gz: afbec95cbbadb5f167ecc59f8e21fd4e7ab4285f97a6d6bc847129c2de03fe43
4
+ data.tar.gz: dc1434040422eda6fe0dca6ba123e6ff51a37df658bcd314be834f67c97f9d66
5
5
  SHA512:
6
- metadata.gz: 8282983f1215feffb37e0541680abd91a44799a95d687cb3adb5cfcb91a1adbf8a07d585fffcd4e477579eebdd9f4a09f0efbc6dfb0b264b0a1a288aa0ac9688
7
- data.tar.gz: f7cafd9924e8e26abc9a6e5783938ebedbea7a0dd68fc69a5980186affab6593f8af4a25c8205e20fbfb45534bec96aa4b5b36bc558084994200a73f8eca31d7
6
+ metadata.gz: 57801abd718d1e5bac281e01a6dfa7e54bc3da9def20f479c6c028b5b8ab8e77dbc7cd2c7e6c6a1ff6ba48cfbc7e81e0b23bb6da81f40050fbc69d6ed460af3a
7
+ data.tar.gz: 23c740466516ec437da7d7a8d909958b63d3aaca75dc3c53d748f5c7c79097c8c86c801396f4ba9e95b8fd16ae5f8cbcb9f59dcf06e0f69050cfcdc1e0ddb0cc
@@ -5,7 +5,7 @@ jobs:
5
5
  strategy:
6
6
  fail-fast: false
7
7
  matrix:
8
- ruby-version: ['2.7', '3.0', '3.1', '3.2']
8
+ ruby-version: ["3.1", "3.2", "3.3"]
9
9
 
10
10
  runs-on: ubuntu-latest
11
11
  env:
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
- ## [2.4.0](2023-27-25)
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 (2.4.0)
4
+ graphql_rails (3.0.0)
5
5
  activesupport (>= 4)
6
- graphql (= 2.0.21)
6
+ graphql (~> 2)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- actioncable (6.1.4.4)
12
- actionpack (= 6.1.4.4)
13
- activesupport (= 6.1.4.4)
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.4.4)
17
- actionpack (= 6.1.4.4)
18
- activejob (= 6.1.4.4)
19
- activerecord (= 6.1.4.4)
20
- activestorage (= 6.1.4.4)
21
- activesupport (= 6.1.4.4)
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.4.4)
24
- actionpack (= 6.1.4.4)
25
- actionview (= 6.1.4.4)
26
- activejob (= 6.1.4.4)
27
- activesupport (= 6.1.4.4)
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.4.4)
31
- actionview (= 6.1.4.4)
32
- activesupport (= 6.1.4.4)
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.4.4)
38
- actionpack (= 6.1.4.4)
39
- activerecord (= 6.1.4.4)
40
- activestorage (= 6.1.4.4)
41
- activesupport (= 6.1.4.4)
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.4.4)
44
- activesupport (= 6.1.4.4)
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.4.4)
50
- activesupport (= 6.1.4.4)
49
+ activejob (6.1.7.10)
50
+ activesupport (= 6.1.7.10)
51
51
  globalid (>= 0.3.6)
52
- activemodel (6.1.4.4)
53
- activesupport (= 6.1.4.4)
54
- activerecord (6.1.4.4)
55
- activemodel (= 6.1.4.4)
56
- activesupport (= 6.1.4.4)
57
- activestorage (6.1.4.4)
58
- actionpack (= 6.1.4.4)
59
- activejob (= 6.1.4.4)
60
- activerecord (= 6.1.4.4)
61
- activesupport (= 6.1.4.4)
62
- marcel (~> 1.0.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.4.4)
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.2)
71
- bson (4.14.0)
72
- builder (3.2.4)
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.1.10)
78
+ concurrent-ruby (1.3.5)
78
79
  crass (1.0.6)
79
- diff-lcs (1.5.0)
80
- docile (1.4.0)
81
- erubi (1.10.0)
82
- globalid (1.0.1)
83
- activesupport (>= 5.0)
84
- graphql (2.0.21)
85
- i18n (1.12.0)
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
- loofah (2.19.1)
93
+ logger (1.6.6)
94
+ loofah (2.24.0)
88
95
  crass (~> 1.0.2)
89
- nokogiri (>= 1.5.9)
90
- mail (2.7.1)
96
+ nokogiri (>= 1.12.0)
97
+ mail (2.8.1)
91
98
  mini_mime (>= 0.1.1)
92
- marcel (1.0.2)
93
- method_source (1.0.0)
94
- mini_mime (1.1.2)
95
- mini_portile2 (2.8.1)
96
- minitest (5.17.0)
97
- mongo (2.17.0)
98
- bson (>= 4.8.2, < 5.0.0)
99
- mongoid (7.3.3)
100
- activemodel (>= 5.1, < 6.2)
101
- mongo (>= 2.10.5, < 3.0.0)
102
- ruby2_keywords (~> 0.0.5)
103
- nio4r (2.5.8)
104
- nokogiri (1.14.3)
105
- mini_portile2 (~> 2.8.0)
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.21.0)
108
- parser (3.1.0.0)
126
+ parallel (1.26.3)
127
+ parser (3.3.7.3)
109
128
  ast (~> 2.4.1)
110
- pry (0.13.1)
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.9.0)
134
+ pry-byebug (3.10.1)
114
135
  byebug (~> 11.0)
115
- pry (~> 0.13.0)
116
- racc (1.6.2)
117
- rack (2.2.6.4)
118
- rack-test (1.1.0)
119
- rack (>= 1.0, < 3)
120
- rails (6.1.4.4)
121
- actioncable (= 6.1.4.4)
122
- actionmailbox (= 6.1.4.4)
123
- actionmailer (= 6.1.4.4)
124
- actionpack (= 6.1.4.4)
125
- actiontext (= 6.1.4.4)
126
- actionview (= 6.1.4.4)
127
- activejob (= 6.1.4.4)
128
- activemodel (= 6.1.4.4)
129
- activerecord (= 6.1.4.4)
130
- activestorage (= 6.1.4.4)
131
- activesupport (= 6.1.4.4)
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.4.4)
154
+ railties (= 6.1.7.10)
134
155
  sprockets-rails (>= 2.0.0)
135
- rails-dom-testing (2.0.3)
136
- activesupport (>= 4.2.0)
156
+ rails-dom-testing (2.2.0)
157
+ activesupport (>= 5.0.0)
158
+ minitest
137
159
  nokogiri (>= 1.6)
138
- rails-html-sanitizer (1.4.4)
139
- loofah (~> 2.19, >= 2.19.1)
140
- railties (6.1.4.4)
141
- actionpack (= 6.1.4.4)
142
- activesupport (= 6.1.4.4)
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 (>= 0.13)
167
+ rake (>= 12.2)
145
168
  thor (~> 1.0)
146
169
  rainbow (3.1.1)
147
- rake (13.0.6)
148
- regexp_parser (2.2.0)
149
- rexml (3.2.5)
150
- rspec (3.10.0)
151
- rspec-core (~> 3.10.0)
152
- rspec-expectations (~> 3.10.0)
153
- rspec-mocks (~> 3.10.0)
154
- rspec-core (3.10.1)
155
- rspec-support (~> 3.10.0)
156
- rspec-expectations (3.10.2)
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.10.0)
159
- rspec-mocks (3.10.2)
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.10.0)
162
- rspec-support (3.10.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.15.1)
173
- parser (>= 3.0.1.1)
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.11.0)
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.12.3)
187
- simplecov_json_formatter (0.1.3)
188
- sprockets (4.0.2)
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 (> 1, < 3)
191
- sprockets-rails (3.4.2)
192
- actionpack (>= 5.2)
193
- activesupport (>= 5.2)
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.1)
196
- tzinfo (2.0.5)
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.5)
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.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 exra arguments, simply pass them to `.decorate` method. Like this:
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
+ ```
@@ -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`:
@@ -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.0.21'
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