graphql_rails 2.3.0 → 3.0.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 (47) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +3 -2
  3. data/CHANGELOG.md +21 -0
  4. data/Gemfile.lock +76 -73
  5. data/docs/README.md +1 -1
  6. data/docs/components/controller.md +15 -1
  7. data/docs/components/model.md +130 -6
  8. data/docs/components/routes.md +20 -10
  9. data/graphql_rails.gemspec +1 -1
  10. data/lib/generators/graphql_rails/templates/graphql_controller.erb +1 -1
  11. data/lib/graphql_rails/attributes/attributable.rb +6 -0
  12. data/lib/graphql_rails/attributes/attribute.rb +22 -9
  13. data/lib/graphql_rails/attributes/attribute_configurable.rb +27 -0
  14. data/lib/graphql_rails/attributes/attribute_name_parser.rb +4 -4
  15. data/lib/graphql_rails/attributes/input_attribute.rb +7 -1
  16. data/lib/graphql_rails/attributes/type_parseable.rb +6 -7
  17. data/lib/graphql_rails/controller/action.rb +4 -4
  18. data/lib/graphql_rails/controller/action_configuration.rb +1 -1
  19. data/lib/graphql_rails/controller/build_controller_action_resolver.rb +4 -15
  20. data/lib/graphql_rails/controller/configuration.rb +7 -2
  21. data/lib/graphql_rails/controller/handle_controller_error.rb +65 -0
  22. data/lib/graphql_rails/controller/log_controller_action.rb +1 -0
  23. data/lib/graphql_rails/controller/request/format_errors.rb +1 -1
  24. data/lib/graphql_rails/controller/request.rb +3 -2
  25. data/lib/graphql_rails/controller.rb +9 -6
  26. data/lib/graphql_rails/decorator/relation_decorator.rb +2 -2
  27. data/lib/graphql_rails/errors/custom_execution_error.rb +1 -1
  28. data/lib/graphql_rails/errors/execution_error.rb +1 -1
  29. data/lib/graphql_rails/model/configuration.rb +15 -2
  30. data/lib/graphql_rails/model/find_or_build_graphql_input_type.rb +36 -0
  31. data/lib/graphql_rails/model/find_or_build_graphql_type.rb +47 -13
  32. data/lib/graphql_rails/model/find_or_build_graphql_type_class.rb +7 -3
  33. data/lib/graphql_rails/model/input.rb +3 -3
  34. data/lib/graphql_rails/router/event_route.rb +52 -0
  35. data/lib/graphql_rails/router/mutation_route.rb +1 -1
  36. data/lib/graphql_rails/router/query_route.rb +1 -1
  37. data/lib/graphql_rails/router/resource_routes_builder.rb +0 -8
  38. data/lib/graphql_rails/router/route.rb +12 -2
  39. data/lib/graphql_rails/router/schema_builder.rb +15 -10
  40. data/lib/graphql_rails/router.rb +8 -8
  41. data/lib/graphql_rails/rspec_controller_helpers.rb +17 -3
  42. data/lib/graphql_rails/types/hidable_by_group.rb +23 -3
  43. data/lib/graphql_rails/types/input_object_type.rb +16 -0
  44. data/lib/graphql_rails/version.rb +1 -1
  45. metadata +10 -14
  46. data/lib/graphql_rails/model/build_graphql_input_type.rb +0 -43
  47. data/lib/graphql_rails/router/subscription_route.rb +0 -22
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f06459a3c8c16e40dffd181d7c08128558e2bdca598845b9e94f51852681e61
4
- data.tar.gz: 1a4ddc9e11a4c5ef22240f7e36b3070bcf89b712c561cad12e41ede1dc18fbc3
3
+ metadata.gz: 47c75badc8873658f461e2bc0f6de0ca35f2c13c7ded2ed66b23b20ee91fc60e
4
+ data.tar.gz: 551a92383fad945d6fb8c03f190793431b485a8a98256a64e26f892c1e48fc2f
5
5
  SHA512:
6
- metadata.gz: 23e0d160c19e3c56c00a474cb77eff10c6a86c3ce1c63f3cdb87f4c374f3c10da79b5f2529a14a026f81e6f3b2c32e9b2fecd671bd7b38066e07d020c65fa93a
7
- data.tar.gz: a0ade6d1ce611baf97ab0a631770273c98953b04eb3991e3234c12a12f21e893962b62a1785ba5da48de7193c366129d29732c7121fbe6c4404d5e1f05cedda2
6
+ metadata.gz: 0e852e9c89ee080ca786abfaabea1162d8ed1eadb4086bf7d2f9908c454e56dc8c839ab05f6a3967859188f3c36f32eae1907b45e41476e24fb81f5fb5db8e29
7
+ data.tar.gz: 0d970a75c022b4635e6c925db92f8d7d22cc67b8e8e41ed8c961c98b2a8aa2c3b4726a29fc736af5151ea935c899b21d454e9af703e9beb6ea9fab378d5fecbf
@@ -3,14 +3,15 @@ on: [push, pull_request]
3
3
  jobs:
4
4
  specs:
5
5
  strategy:
6
+ fail-fast: false
6
7
  matrix:
7
- ruby-version: ['2.7', '3.0', '3.1']
8
+ ruby-version: ['3.0', '3.1', '3.2', '3.3']
8
9
 
9
10
  runs-on: ubuntu-latest
10
11
  env:
11
12
  CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
12
13
  steps:
13
- - uses: actions/checkout@v2
14
+ - uses: actions/checkout@v3
14
15
  - uses: ruby/setup-ruby@v1
15
16
  with:
16
17
  ruby-version: ${{ matrix.ruby-version }}
data/CHANGELOG.md CHANGED
@@ -9,6 +9,27 @@ 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
+ ## [3.0.0](2024-05-31)
13
+
14
+ * Added: `input.attribute.property` method which allows aliasing input parameter keys
15
+ * Added: possibility to copy attribute config using the `Attribute#same_as` method
16
+ * Fixed: do not ignore custom `max_page_size` for paginated responses
17
+ * Fixed: do not ignore custom `default_page_size` and other options for paginated responses
18
+ * Fixed: do not crash when using deeply nested input definitions
19
+ * Added: `rescue_from` support in controllers
20
+ * Added: Bumped graphql version to 2.1.7
21
+ * Added: `implements` support in models
22
+ * Added: `response.controller` and `response.action_name` methods in RSpecControllerHelpers
23
+ * Removed: stop supporting ruby < 3.0.0
24
+
25
+ ## [2.4.0](2023-11-25)
26
+
27
+ * Added: `hidden_in_groups` for attributes to be able to skip attribute from certain groups
28
+ * Added: `extras` for attributes to be able to include graphql-ruby extensions
29
+ * Added: `lookahead` as a controller request object field
30
+ * Changed: `subscription` definition to `event` definition in router configuration page
31
+ * Fixed: avoid "Found two visible definitions for X" issues for input types
32
+
12
33
  ## [2.3.0](2022-11-25)
13
34
 
14
35
  * Added support for Ruby 3.1.2, keyword arguments for decorators support included
data/Gemfile.lock CHANGED
@@ -1,67 +1,67 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- graphql_rails (2.3.0)
4
+ graphql_rails (3.0.0)
5
5
  activesupport (>= 4)
6
- graphql (~> 1.12, >= 1.12.4)
6
+ graphql (= 2.1.7)
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.1)
12
+ actionpack (= 6.1.7.1)
13
+ activesupport (= 6.1.7.1)
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.1)
17
+ actionpack (= 6.1.7.1)
18
+ activejob (= 6.1.7.1)
19
+ activerecord (= 6.1.7.1)
20
+ activestorage (= 6.1.7.1)
21
+ activesupport (= 6.1.7.1)
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.1)
24
+ actionpack (= 6.1.7.1)
25
+ actionview (= 6.1.7.1)
26
+ activejob (= 6.1.7.1)
27
+ activesupport (= 6.1.7.1)
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.1)
31
+ actionview (= 6.1.7.1)
32
+ activesupport (= 6.1.7.1)
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.1)
38
+ actionpack (= 6.1.7.1)
39
+ activerecord (= 6.1.7.1)
40
+ activestorage (= 6.1.7.1)
41
+ activesupport (= 6.1.7.1)
42
42
  nokogiri (>= 1.8.5)
43
- actionview (6.1.4.4)
44
- activesupport (= 6.1.4.4)
43
+ actionview (6.1.7.1)
44
+ activesupport (= 6.1.7.1)
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.1)
50
+ activesupport (= 6.1.7.1)
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.1)
53
+ activesupport (= 6.1.7.1)
54
+ activerecord (6.1.7.1)
55
+ activemodel (= 6.1.7.1)
56
+ activesupport (= 6.1.7.1)
57
+ activestorage (6.1.7.1)
58
+ actionpack (= 6.1.7.1)
59
+ activejob (= 6.1.7.1)
60
+ activerecord (= 6.1.7.1)
61
+ activesupport (= 6.1.7.1)
62
+ marcel (~> 1.0)
63
63
  mini_mime (>= 1.1.0)
64
- activesupport (6.1.4.4)
64
+ activesupport (6.1.7.1)
65
65
  concurrent-ruby (~> 1.0, >= 1.0.2)
66
66
  i18n (>= 1.6, < 2)
67
67
  minitest (>= 5.1)
@@ -74,17 +74,18 @@ GEM
74
74
  codecov (0.6.0)
75
75
  simplecov (>= 0.15, < 0.22)
76
76
  coderay (1.1.3)
77
- concurrent-ruby (1.1.9)
77
+ concurrent-ruby (1.3.1)
78
78
  crass (1.0.6)
79
79
  diff-lcs (1.5.0)
80
80
  docile (1.4.0)
81
81
  erubi (1.10.0)
82
- globalid (1.0.0)
82
+ globalid (1.0.1)
83
83
  activesupport (>= 5.0)
84
- graphql (1.13.17)
85
- i18n (1.8.11)
84
+ graphql (2.1.7)
85
+ racc (~> 1.4)
86
+ i18n (1.14.5)
86
87
  concurrent-ruby (~> 1.0)
87
- loofah (2.18.0)
88
+ loofah (2.19.1)
88
89
  crass (~> 1.0.2)
89
90
  nokogiri (>= 1.5.9)
90
91
  mail (2.7.1)
@@ -92,8 +93,8 @@ GEM
92
93
  marcel (1.0.2)
93
94
  method_source (1.0.0)
94
95
  mini_mime (1.1.2)
95
- mini_portile2 (2.8.0)
96
- minitest (5.15.0)
96
+ mini_portile2 (2.8.6)
97
+ minitest (5.23.1)
97
98
  mongo (2.17.0)
98
99
  bson (>= 4.8.2, < 5.0.0)
99
100
  mongoid (7.3.3)
@@ -101,8 +102,8 @@ GEM
101
102
  mongo (>= 2.10.5, < 3.0.0)
102
103
  ruby2_keywords (~> 0.0.5)
103
104
  nio4r (2.5.8)
104
- nokogiri (1.13.9)
105
- mini_portile2 (~> 2.8.0)
105
+ nokogiri (1.16.5)
106
+ mini_portile2 (~> 2.8.2)
106
107
  racc (~> 1.4)
107
108
  parallel (1.21.0)
108
109
  parser (3.1.0.0)
@@ -113,40 +114,41 @@ GEM
113
114
  pry-byebug (3.9.0)
114
115
  byebug (~> 11.0)
115
116
  pry (~> 0.13.0)
116
- racc (1.6.0)
117
- rack (2.2.3.1)
117
+ racc (1.8.0)
118
+ rack (2.2.9)
118
119
  rack-test (1.1.0)
119
120
  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)
121
+ rails (6.1.7.1)
122
+ actioncable (= 6.1.7.1)
123
+ actionmailbox (= 6.1.7.1)
124
+ actionmailer (= 6.1.7.1)
125
+ actionpack (= 6.1.7.1)
126
+ actiontext (= 6.1.7.1)
127
+ actionview (= 6.1.7.1)
128
+ activejob (= 6.1.7.1)
129
+ activemodel (= 6.1.7.1)
130
+ activerecord (= 6.1.7.1)
131
+ activestorage (= 6.1.7.1)
132
+ activesupport (= 6.1.7.1)
132
133
  bundler (>= 1.15.0)
133
- railties (= 6.1.4.4)
134
+ railties (= 6.1.7.1)
134
135
  sprockets-rails (>= 2.0.0)
135
136
  rails-dom-testing (2.0.3)
136
137
  activesupport (>= 4.2.0)
137
138
  nokogiri (>= 1.6)
138
- rails-html-sanitizer (1.4.3)
139
- loofah (~> 2.3)
140
- railties (6.1.4.4)
141
- actionpack (= 6.1.4.4)
142
- activesupport (= 6.1.4.4)
139
+ rails-html-sanitizer (1.4.4)
140
+ loofah (~> 2.19, >= 2.19.1)
141
+ railties (6.1.7.1)
142
+ actionpack (= 6.1.7.1)
143
+ activesupport (= 6.1.7.1)
143
144
  method_source
144
- rake (>= 0.13)
145
+ rake (>= 12.2)
145
146
  thor (~> 1.0)
146
147
  rainbow (3.1.1)
147
148
  rake (13.0.6)
148
149
  regexp_parser (2.2.0)
149
- rexml (3.2.5)
150
+ rexml (3.2.8)
151
+ strscan (>= 3.0.9)
150
152
  rspec (3.10.0)
151
153
  rspec-core (~> 3.10.0)
152
154
  rspec-expectations (~> 3.10.0)
@@ -192,14 +194,15 @@ GEM
192
194
  actionpack (>= 5.2)
193
195
  activesupport (>= 5.2)
194
196
  sprockets (>= 3.0.0)
197
+ strscan (3.1.0)
195
198
  thor (1.2.1)
196
- tzinfo (2.0.4)
199
+ tzinfo (2.0.6)
197
200
  concurrent-ruby (~> 1.0)
198
201
  unicode-display_width (1.8.0)
199
202
  websocket-driver (0.7.5)
200
203
  websocket-extensions (>= 0.1.0)
201
204
  websocket-extensions (0.1.5)
202
- zeitwerk (2.5.3)
205
+ zeitwerk (2.6.15)
203
206
 
204
207
  PLATFORMS
205
208
  ruby
data/docs/README.md CHANGED
@@ -92,7 +92,7 @@ class Graphql::UsersController < GraphqlApplicationController
92
92
  end
93
93
  ```
94
94
 
95
- See [Controller docs](components/controlle.md) for more info.
95
+ See [Controller docs](components/controller.md) for more info.
96
96
 
97
97
  ## Testing your GraphqlRails::Controller in RSpec
98
98
 
@@ -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
  ```
@@ -101,7 +101,7 @@ Check [graphql-ruby documentation](https://graphql-ruby.org) for more details ab
101
101
 
102
102
  ### attribute.property
103
103
 
104
- By default graphql attribute names are expected to be same as model methods/attributes, but if you want to use different name on grapqhl side, you can use `property` option:
104
+ By default graphql attribute names are expected to be same as model methods/attributes, but if you want to use different name on graphql side, you can use `property` option:
105
105
 
106
106
  ```ruby
107
107
  class User
@@ -185,6 +185,24 @@ class User
185
185
  end
186
186
  ```
187
187
 
188
+ ### attribute.hidden_in_groups
189
+
190
+ Opposite for Attribute#groups. It hides attribute in given groups
191
+
192
+ ```ruby
193
+ class User
194
+ include GraphqlRails::Model
195
+
196
+ graphql do |c|
197
+ # visible in all schemas (default):
198
+ c.attribute(:email)
199
+
200
+ # visible in all schemas except "external":
201
+ c.attribute(:nickname).hidden_in_groups(:external)
202
+ end
203
+ end
204
+ ```
205
+
188
206
  ### attribute.options
189
207
 
190
208
  Allows passing options to attribute definition. Available options:
@@ -200,6 +218,21 @@ class User
200
218
  c.attribute :first_name, options: { attribute_name_format: :original } # will be accessible as first_name from client side
201
219
  end
202
220
  end
221
+ ```
222
+
223
+ ### attribute.extras
224
+
225
+ Allows passing extras to enable [graphql-ruby field extensions](https://graphql-ruby.org/type_definitions/field_extensions.html#using-extras)
226
+
227
+ ```ruby
228
+ class User
229
+ include GraphqlRails::Model
230
+
231
+ graphql do |c|
232
+ c.attribute(:items).extras([:lookahead])
233
+ end
234
+ end
235
+ ```
203
236
 
204
237
  ### attribute.permit
205
238
 
@@ -303,7 +336,7 @@ You can mark collection method as `paginated`. In this case method will return r
303
336
  class User
304
337
  include GraphqlRails::Model
305
338
 
306
- graphql.attribute :items, type: '[Item]', paginatted: true
339
+ graphql.attribute :items, type: '[Item]', paginated: true
307
340
 
308
341
  def items
309
342
  Item.all
@@ -335,6 +368,21 @@ class User
335
368
  end
336
369
  ```
337
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
+
338
386
  ### attribute.with
339
387
 
340
388
  When you want to define some options dynamically, it's quite handy to use "Attribute#with" method:
@@ -388,7 +436,7 @@ end
388
436
 
389
437
  ## name
390
438
 
391
- By default grapqhl type name will be same as model name, but you can change it via `name` method
439
+ By default graphql type name will be same as model name, but you can change it via `name` method
392
440
 
393
441
  ```ruby
394
442
  class User
@@ -402,7 +450,7 @@ end
402
450
 
403
451
  ## description
404
452
 
405
- To improve grapqhl documentation, you can description for your graphql type:
453
+ To improve graphql documentation, you can description for your graphql type:
406
454
 
407
455
  ```ruby
408
456
  class User
@@ -414,12 +462,36 @@ class User
414
462
  end
415
463
  ```
416
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
+
417
489
  ## graphql_type
418
490
 
419
491
  Sometimes it's handy to get raw graphql type. To do so you can call:
420
492
 
421
493
  ```ruby
422
- YourModel.graphql.grapqhl_type
494
+ YourModel.graphql.graphql_type
423
495
  ```
424
496
 
425
497
  ## input
@@ -555,7 +627,6 @@ class User
555
627
  end
556
628
  ```
557
629
 
558
-
559
630
  #### input attribute deprecation
560
631
 
561
632
  You can mark input attribute as deprecated with `deprecated` method:
@@ -585,6 +656,59 @@ class User
585
656
  end
586
657
  ```
587
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
+
588
712
  ## graphql_context
589
713
 
590
714
  It's possible to access graphql_context in your model using method `graphql_context`:
@@ -21,10 +21,10 @@ MyGraphqlSchema = GraphqlRails::Router.draw do
21
21
 
22
22
  # you can use namespaced controllers too:
23
23
  scope module: 'admin' do
24
- # `updateTranslations` route will be handeled by `Admin::TranslationsController`
24
+ # `updateTranslations` route will be handled by `Admin::TranslationsController`
25
25
  mutation :updateTranslations, to: 'translations#update'
26
26
 
27
- # all :groups routes will be handeled by `Admin::GroupsController`
27
+ # all :groups routes will be handled by `Admin::GroupsController`
28
28
  resources :groups
29
29
  end
30
30
  end
@@ -40,9 +40,9 @@ If you want to exclude some actions you can use `only` or `except` options.
40
40
 
41
41
  ```ruby
42
42
  MyGraphqlSchema = GraphqlRails::Router.draw do
43
- resouces :users
44
- resouces :friends, only: :index
45
- resouces :posts, except: [:destroy, :index]
43
+ resources :users
44
+ resources :friends, only: :index
45
+ resources :posts, except: [:destroy, :index]
46
46
  end
47
47
  ```
48
48
 
@@ -52,7 +52,7 @@ Sometimes it's handy so have non-CRUD actions in your controller. To define such
52
52
 
53
53
  ```ruby
54
54
  MyGraphqlSchema = GraphqlRails::Router.draw do
55
- resouces :users do
55
+ resources :users do
56
56
  mutation :changePassword, on: :member
57
57
  query :active, on: :collection
58
58
  end
@@ -65,7 +65,7 @@ Sometimes, especially when working with member queries, it sounds better when ac
65
65
 
66
66
  ```ruby
67
67
  MyGraphqlSchema = GraphqlRails::Router.draw do
68
- resouces :users do
68
+ resources :users do
69
69
  query :details, on: :member, suffix: true
70
70
  end
71
71
  end
@@ -73,15 +73,25 @@ end
73
73
 
74
74
  This will generate `userDetails` field on GraphQL side.
75
75
 
76
- ## _query_ and _mutation_ & _subscription_
76
+ ## _query_ and _mutation_ & _event_
77
+
78
+ In case you want to have non-CRUD controller with custom actions you can define your own `query`/`mutation` actions like this:
79
+
80
+ ```ruby
81
+ MyGraphqlSchema = GraphqlRails::Router.draw do
82
+ mutation :logIn, to: 'sessions#login'
83
+ query :me, to: 'users#current_user'
84
+ end
77
85
 
78
- in case you want to have non-CRUD controller with custom actions you can define your own `query`/`mutation`/`subscription` actions like this:
86
+ Subscriptions are not really controller actions with a single response type, thus, they're defined differently. In GraphQL you subscribe to event, for example `userCreated`. To do this in graphql_rails you would define `event :user_created` in router definition.
79
87
 
80
88
  ```ruby
81
89
  MyGraphqlSchema = GraphqlRails::Router.draw do
82
90
  mutation :logIn, to: 'sessions#login'
83
91
  query :me, to: 'users#current_user'
84
- subscribtion :new_message, to: 'messages#created'
92
+
93
+ event :user_created # expects Subscriptions::UserCreatedSubscription class to be present
94
+ event :user_deleted, subscription_class: 'Subscriptions::UserDeletedSubscription'
85
95
  end
86
96
  ```
87
97
 
@@ -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', '~> 1.12', '>= 1.12.4'
23
+ spec.add_dependency 'graphql', '2.1.7'
24
24
  spec.add_dependency 'activesupport', '>= 4'
25
25
 
26
26
  spec.add_development_dependency 'bundler', '~> 2'
@@ -12,7 +12,7 @@ class GraphqlController < ApplicationController
12
12
 
13
13
  private
14
14
 
15
- # data defined here will be accessible via `grapqhl_request.context`
15
+ # data defined here will be accessible via `graphql_request.context`
16
16
  # in GraphqlRails::Controller instances
17
17
  def graphql_context
18
18
  {}
@@ -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