graphql_rails 2.3.0 → 3.0.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 +3 -2
- data/CHANGELOG.md +21 -0
- data/Gemfile.lock +76 -73
- data/docs/README.md +1 -1
- data/docs/components/controller.md +15 -1
- data/docs/components/model.md +130 -6
- data/docs/components/routes.md +20 -10
- data/graphql_rails.gemspec +1 -1
- data/lib/generators/graphql_rails/templates/graphql_controller.erb +1 -1
- data/lib/graphql_rails/attributes/attributable.rb +6 -0
- data/lib/graphql_rails/attributes/attribute.rb +22 -9
- data/lib/graphql_rails/attributes/attribute_configurable.rb +27 -0
- data/lib/graphql_rails/attributes/attribute_name_parser.rb +4 -4
- data/lib/graphql_rails/attributes/input_attribute.rb +7 -1
- data/lib/graphql_rails/attributes/type_parseable.rb +6 -7
- data/lib/graphql_rails/controller/action.rb +4 -4
- data/lib/graphql_rails/controller/action_configuration.rb +1 -1
- data/lib/graphql_rails/controller/build_controller_action_resolver.rb +4 -15
- data/lib/graphql_rails/controller/configuration.rb +7 -2
- 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/format_errors.rb +1 -1
- data/lib/graphql_rails/controller/request.rb +3 -2
- data/lib/graphql_rails/controller.rb +9 -6
- data/lib/graphql_rails/decorator/relation_decorator.rb +2 -2
- data/lib/graphql_rails/errors/custom_execution_error.rb +1 -1
- data/lib/graphql_rails/errors/execution_error.rb +1 -1
- data/lib/graphql_rails/model/configuration.rb +15 -2
- data/lib/graphql_rails/model/find_or_build_graphql_input_type.rb +36 -0
- data/lib/graphql_rails/model/find_or_build_graphql_type.rb +47 -13
- data/lib/graphql_rails/model/find_or_build_graphql_type_class.rb +7 -3
- data/lib/graphql_rails/model/input.rb +3 -3
- data/lib/graphql_rails/router/event_route.rb +52 -0
- data/lib/graphql_rails/router/mutation_route.rb +1 -1
- data/lib/graphql_rails/router/query_route.rb +1 -1
- data/lib/graphql_rails/router/resource_routes_builder.rb +0 -8
- data/lib/graphql_rails/router/route.rb +12 -2
- data/lib/graphql_rails/router/schema_builder.rb +15 -10
- data/lib/graphql_rails/router.rb +8 -8
- data/lib/graphql_rails/rspec_controller_helpers.rb +17 -3
- data/lib/graphql_rails/types/hidable_by_group.rb +23 -3
- data/lib/graphql_rails/types/input_object_type.rb +16 -0
- data/lib/graphql_rails/version.rb +1 -1
- metadata +10 -14
- data/lib/graphql_rails/model/build_graphql_input_type.rb +0 -43
- 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47c75badc8873658f461e2bc0f6de0ca35f2c13c7ded2ed66b23b20ee91fc60e
|
4
|
+
data.tar.gz: 551a92383fad945d6fb8c03f190793431b485a8a98256a64e26f892c1e48fc2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e852e9c89ee080ca786abfaabea1162d8ed1eadb4086bf7d2f9908c454e56dc8c839ab05f6a3967859188f3c36f32eae1907b45e41476e24fb81f5fb5db8e29
|
7
|
+
data.tar.gz: 0d970a75c022b4635e6c925db92f8d7d22cc67b8e8e41ed8c961c98b2a8aa2c3b4726a29fc736af5151ea935c899b21d454e9af703e9beb6ea9fab378d5fecbf
|
data/.github/workflows/ruby.yml
CHANGED
@@ -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: ['
|
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@
|
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 (
|
4
|
+
graphql_rails (3.0.0)
|
5
5
|
activesupport (>= 4)
|
6
|
-
graphql (
|
6
|
+
graphql (= 2.1.7)
|
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.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.
|
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.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.
|
24
|
-
actionpack (= 6.1.
|
25
|
-
actionview (= 6.1.
|
26
|
-
activejob (= 6.1.
|
27
|
-
activesupport (= 6.1.
|
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.
|
31
|
-
actionview (= 6.1.
|
32
|
-
activesupport (= 6.1.
|
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.
|
38
|
-
actionpack (= 6.1.
|
39
|
-
activerecord (= 6.1.
|
40
|
-
activestorage (= 6.1.
|
41
|
-
activesupport (= 6.1.
|
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.
|
44
|
-
activesupport (= 6.1.
|
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.
|
50
|
-
activesupport (= 6.1.
|
49
|
+
activejob (6.1.7.1)
|
50
|
+
activesupport (= 6.1.7.1)
|
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.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.
|
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
|
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.
|
82
|
+
globalid (1.0.1)
|
83
83
|
activesupport (>= 5.0)
|
84
|
-
graphql (1.
|
85
|
-
|
84
|
+
graphql (2.1.7)
|
85
|
+
racc (~> 1.4)
|
86
|
+
i18n (1.14.5)
|
86
87
|
concurrent-ruby (~> 1.0)
|
87
|
-
loofah (2.
|
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.
|
96
|
-
minitest (5.
|
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.
|
105
|
-
mini_portile2 (~> 2.8.
|
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.
|
117
|
-
rack (2.2.
|
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.
|
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.
|
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.
|
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.
|
139
|
-
loofah (~> 2.
|
140
|
-
railties (6.1.
|
141
|
-
actionpack (= 6.1.
|
142
|
-
activesupport (= 6.1.
|
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 (>=
|
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.
|
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.
|
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.
|
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/
|
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
|
```
|
data/docs/components/model.md
CHANGED
@@ -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
|
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]',
|
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
|
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
|
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.
|
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`:
|
data/docs/components/routes.md
CHANGED
@@ -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
|
24
|
+
# `updateTranslations` route will be handled by `Admin::TranslationsController`
|
25
25
|
mutation :updateTranslations, to: 'translations#update'
|
26
26
|
|
27
|
-
# all :groups routes will be
|
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
|
-
|
44
|
-
|
45
|
-
|
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
|
-
|
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
|
-
|
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_ &
|
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
|
-
|
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
|
-
|
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
|
|
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', '
|
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 `
|
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
|