graphql_rails 1.2.4 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +18 -0
  3. data/.hound.yml +1 -1
  4. data/.rubocop.yml +4 -0
  5. data/.ruby-version +1 -1
  6. data/CHANGELOG.md +21 -0
  7. data/Gemfile +3 -3
  8. data/Gemfile.lock +129 -128
  9. data/docs/README.md +1 -1
  10. data/docs/components/model.md +107 -13
  11. data/docs/components/routes.md +4 -3
  12. data/docs/other_tools/schema_dump.md +8 -8
  13. data/lib/graphql_rails/attributes/attributable.rb +6 -14
  14. data/lib/graphql_rails/attributes/attribute.rb +10 -34
  15. data/lib/graphql_rails/attributes/attribute_configurable.rb +45 -0
  16. data/lib/graphql_rails/attributes/attribute_name_parser.rb +7 -7
  17. data/lib/graphql_rails/attributes/input_attribute.rb +20 -14
  18. data/lib/graphql_rails/attributes/input_type_parser.rb +5 -7
  19. data/lib/graphql_rails/attributes/type_parseable.rb +49 -19
  20. data/lib/graphql_rails/attributes/type_parser.rb +4 -9
  21. data/lib/graphql_rails/concerns/chainable_options.rb +49 -0
  22. data/lib/graphql_rails/controller/build_controller_action_resolver/controller_action_resolver.rb +3 -0
  23. data/lib/graphql_rails/controller/log_controller_action.rb +7 -2
  24. data/lib/graphql_rails/decorator/relation_decorator.rb +2 -2
  25. data/lib/graphql_rails/input_configurable.rb +11 -9
  26. data/lib/graphql_rails/model/build_graphql_input_type.rb +4 -2
  27. data/lib/graphql_rails/model/configurable.rb +30 -8
  28. data/lib/graphql_rails/model/configuration.rb +8 -12
  29. data/lib/graphql_rails/model/find_or_build_graphql_type.rb +16 -19
  30. data/lib/graphql_rails/model/find_or_build_graphql_type_class.rb +2 -1
  31. data/lib/graphql_rails/model/input.rb +10 -26
  32. data/lib/graphql_rails/query_runner.rb +9 -3
  33. data/lib/graphql_rails/router/mutation_route.rb +4 -0
  34. data/lib/graphql_rails/router/query_route.rb +4 -0
  35. data/lib/graphql_rails/router/resource_routes_builder.rb +8 -0
  36. data/lib/graphql_rails/router/route.rb +2 -2
  37. data/lib/graphql_rails/router/schema_builder.rb +12 -3
  38. data/lib/graphql_rails/router/subscription_route.rb +22 -0
  39. data/lib/graphql_rails/router.rb +8 -2
  40. data/lib/graphql_rails/tasks/dump_graphql_schema.rb +18 -27
  41. data/lib/graphql_rails/tasks/dump_graphql_schemas.rb +57 -0
  42. data/lib/graphql_rails/tasks/schema.rake +8 -5
  43. data/lib/graphql_rails/types/argument_type.rb +12 -0
  44. data/lib/graphql_rails/types/field_type.rb +14 -0
  45. data/lib/graphql_rails/types/hidable_by_group.rb +32 -0
  46. data/lib/graphql_rails/types/object_type.rb +12 -0
  47. data/lib/graphql_rails/version.rb +1 -1
  48. metadata +16 -8
  49. data/.travis.yml +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4fde3149c0119edc09198e27b61c428ed666ea2bb4582b428142db31a58749c4
4
- data.tar.gz: d9faa17f35d1ac01400b829983d6a2b16230c62971bb6ed0178b9a6bf4b1c0bd
3
+ metadata.gz: 1909c3b76c9addab63bcc0337232c147ceebde0d1f2252da93606b48d1843c64
4
+ data.tar.gz: 6b405941e4bae0e98abbcc07b93ac1a95fa22bcbdfcaa962d241740a15453ba7
5
5
  SHA512:
6
- metadata.gz: ee735c639cf392c7a4261db07791bb953942977fd4c001fcb101fd3e4a7009db58fb27520d0227e2b3254fdbc5d2dc52043d892597e99d4526ad18fc8919de30
7
- data.tar.gz: 80e3a427bb04a91332230460638d7f866afc843dbebfd9e9211454869154c32459e9c1d3c2dcaa97e06bd767792bc6ff742b871ded561094354bc4beab2517a1
6
+ metadata.gz: f5292647cd5c49c51bec7f9f1df33be882637ac83bd54fb23259fc2b5c6d8f351f3501c5db23f0ff7c10daafafed531b4026ff3790ff281cfd71890ff2b2c007
7
+ data.tar.gz: 054adf43e83c54be23fb33547ee521e17ae8f180f5f4c05bf3a7b78f554367e6531483d9bf66af75fe4567940f2931c56f93c2adc6af412efba8e644043af8bc
@@ -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
@@ -1,4 +1,4 @@
1
1
  rubocop:
2
2
  config_file: .rubocop.yml
3
- version: 0.91.0
3
+ version: 1.5.2
4
4
  fail_on_violations: true
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
- 2.7.1
1
+ 3.0.1
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
+ ## [2.2.0](2022-01-25)
13
+
14
+ * Added: support for subscription type
15
+ * Fixed: correctly detect all graphql-ruby objects when using stringified types
16
+ * Added: make code compatible with newer graphql-ruby version
17
+
18
+ ## [2.1.0](2022-01-12)
19
+
20
+ * Added: decorated relations now can be called using "find", "empty?" and "find_by" methods
21
+ * Fixed: allow to define graphql-ruby enum classes as strings.
22
+ * Added: add "groups" to attributes.
23
+ * Changed: `date` type is now alias for `GraphQL::Types::ISO8601Date`, also added aliases for other common graphql-graphql types.
24
+
25
+ ## [2.0.0](2021-12-03)
26
+
27
+ * Added: support for generating multiple schema dumps with `rake graphql_rails:schema:dump`.
28
+ * Added: support for using chainable syntax for input attributes.
29
+ * Changed: changed default `predicate method type from `Boolean` to `Boolean!`
30
+ * Changed: changed error message when trying to paginate not supported types
31
+ * Added: support defining graphql-ruby types as strings.
32
+
12
33
  ## [1.2.4](2021-05-05)
13
34
 
14
35
  * Fixed: Dynamic types definition where type A references type B referencing type A.
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', '0.91.0'
9
- gem 'rubocop-performance', '~> 1.8', '>= 1.8.1'
10
- gem 'rubocop-rspec', '~> 1.44', '>= 1.44.1'
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,112 +1,111 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- graphql_rails (1.2.3)
4
+ graphql_rails (2.2.0)
5
5
  activesupport (>= 4)
6
6
  graphql (~> 1.12, >= 1.12.4)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- actioncable (6.0.3.4)
12
- actionpack (= 6.0.3.4)
11
+ actioncable (6.1.4.4)
12
+ actionpack (= 6.1.4.4)
13
+ activesupport (= 6.1.4.4)
13
14
  nio4r (~> 2.0)
14
15
  websocket-driver (>= 0.6.1)
15
- actionmailbox (6.0.3.4)
16
- actionpack (= 6.0.3.4)
17
- activejob (= 6.0.3.4)
18
- activerecord (= 6.0.3.4)
19
- activestorage (= 6.0.3.4)
20
- activesupport (= 6.0.3.4)
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)
21
22
  mail (>= 2.7.1)
22
- actionmailer (6.0.3.4)
23
- actionpack (= 6.0.3.4)
24
- actionview (= 6.0.3.4)
25
- activejob (= 6.0.3.4)
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)
26
28
  mail (~> 2.5, >= 2.5.4)
27
29
  rails-dom-testing (~> 2.0)
28
- actionpack (6.0.3.4)
29
- actionview (= 6.0.3.4)
30
- activesupport (= 6.0.3.4)
31
- rack (~> 2.0, >= 2.0.8)
30
+ actionpack (6.1.4.4)
31
+ actionview (= 6.1.4.4)
32
+ activesupport (= 6.1.4.4)
33
+ rack (~> 2.0, >= 2.0.9)
32
34
  rack-test (>= 0.6.3)
33
35
  rails-dom-testing (~> 2.0)
34
36
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
35
- actiontext (6.0.3.4)
36
- actionpack (= 6.0.3.4)
37
- activerecord (= 6.0.3.4)
38
- activestorage (= 6.0.3.4)
39
- activesupport (= 6.0.3.4)
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)
40
42
  nokogiri (>= 1.8.5)
41
- actionview (6.0.3.4)
42
- activesupport (= 6.0.3.4)
43
+ actionview (6.1.4.4)
44
+ activesupport (= 6.1.4.4)
43
45
  builder (~> 3.1)
44
46
  erubi (~> 1.4)
45
47
  rails-dom-testing (~> 2.0)
46
48
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
47
- activejob (6.0.3.4)
48
- activesupport (= 6.0.3.4)
49
+ activejob (6.1.4.4)
50
+ activesupport (= 6.1.4.4)
49
51
  globalid (>= 0.3.6)
50
- activemodel (6.0.3.4)
51
- activesupport (= 6.0.3.4)
52
- activerecord (6.0.3.4)
53
- activemodel (= 6.0.3.4)
54
- activesupport (= 6.0.3.4)
55
- activestorage (6.0.3.4)
56
- actionpack (= 6.0.3.4)
57
- activejob (= 6.0.3.4)
58
- activerecord (= 6.0.3.4)
59
- marcel (~> 0.3.1)
60
- activesupport (6.0.3.4)
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)
63
+ mini_mime (>= 1.1.0)
64
+ activesupport (6.1.4.4)
61
65
  concurrent-ruby (~> 1.0, >= 1.0.2)
62
- i18n (>= 0.7, < 2)
63
- minitest (~> 5.1)
64
- tzinfo (~> 1.1)
65
- zeitwerk (~> 2.2, >= 2.2.2)
66
- ast (2.4.1)
67
- bson (4.11.0)
66
+ i18n (>= 1.6, < 2)
67
+ minitest (>= 5.1)
68
+ tzinfo (~> 2.0)
69
+ zeitwerk (~> 2.3)
70
+ ast (2.4.2)
71
+ bson (4.14.0)
68
72
  builder (3.2.4)
69
73
  byebug (11.1.3)
70
- codecov (0.2.12)
71
- json
72
- simplecov
74
+ codecov (0.6.0)
75
+ simplecov (>= 0.15, < 0.22)
73
76
  coderay (1.1.3)
74
- concurrent-ruby (1.1.7)
77
+ concurrent-ruby (1.1.9)
75
78
  crass (1.0.6)
76
- diff-lcs (1.4.4)
77
- docile (1.3.2)
78
- erubi (1.9.0)
79
- globalid (0.4.2)
80
- activesupport (>= 4.2.0)
81
- graphql (1.12.4)
82
- i18n (1.8.5)
79
+ diff-lcs (1.5.0)
80
+ docile (1.4.0)
81
+ erubi (1.10.0)
82
+ globalid (1.0.0)
83
+ activesupport (>= 5.0)
84
+ graphql (1.13.6)
85
+ i18n (1.8.11)
83
86
  concurrent-ruby (~> 1.0)
84
- json (2.3.1)
85
- loofah (2.7.0)
87
+ loofah (2.13.0)
86
88
  crass (~> 1.0.2)
87
89
  nokogiri (>= 1.5.9)
88
90
  mail (2.7.1)
89
91
  mini_mime (>= 0.1.1)
90
- marcel (0.3.3)
91
- mimemagic (~> 0.3.2)
92
+ marcel (1.0.2)
92
93
  method_source (1.0.0)
93
- mimemagic (0.3.10)
94
- nokogiri (~> 1)
95
- rake
96
- mini_mime (1.0.2)
97
- mini_portile2 (2.5.0)
98
- minitest (5.14.2)
99
- mongo (2.13.1)
94
+ mini_mime (1.1.2)
95
+ mini_portile2 (2.7.1)
96
+ minitest (5.15.0)
97
+ mongo (2.17.0)
100
98
  bson (>= 4.8.2, < 5.0.0)
101
- mongoid (7.1.4)
102
- activemodel (>= 5.1, < 6.1)
103
- mongo (>= 2.7.0, < 3.0.0)
104
- nio4r (2.5.4)
105
- nokogiri (1.11.1)
106
- mini_portile2 (~> 2.5.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.13.1)
105
+ mini_portile2 (~> 2.7.0)
107
106
  racc (~> 1.4)
108
- parallel (1.19.2)
109
- parser (2.7.2.0)
107
+ parallel (1.21.0)
108
+ parser (3.1.0.0)
110
109
  ast (~> 2.4.1)
111
110
  pry (0.13.1)
112
111
  coderay (~> 1.1)
@@ -114,91 +113,93 @@ GEM
114
113
  pry-byebug (3.9.0)
115
114
  byebug (~> 11.0)
116
115
  pry (~> 0.13.0)
117
- racc (1.5.2)
116
+ racc (1.6.0)
118
117
  rack (2.2.3)
119
118
  rack-test (1.1.0)
120
119
  rack (>= 1.0, < 3)
121
- rails (6.0.3.4)
122
- actioncable (= 6.0.3.4)
123
- actionmailbox (= 6.0.3.4)
124
- actionmailer (= 6.0.3.4)
125
- actionpack (= 6.0.3.4)
126
- actiontext (= 6.0.3.4)
127
- actionview (= 6.0.3.4)
128
- activejob (= 6.0.3.4)
129
- activemodel (= 6.0.3.4)
130
- activerecord (= 6.0.3.4)
131
- activestorage (= 6.0.3.4)
132
- activesupport (= 6.0.3.4)
133
- bundler (>= 1.3.0)
134
- railties (= 6.0.3.4)
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)
132
+ bundler (>= 1.15.0)
133
+ railties (= 6.1.4.4)
135
134
  sprockets-rails (>= 2.0.0)
136
135
  rails-dom-testing (2.0.3)
137
136
  activesupport (>= 4.2.0)
138
137
  nokogiri (>= 1.6)
139
- rails-html-sanitizer (1.3.0)
138
+ rails-html-sanitizer (1.4.2)
140
139
  loofah (~> 2.3)
141
- railties (6.0.3.4)
142
- actionpack (= 6.0.3.4)
143
- activesupport (= 6.0.3.4)
140
+ railties (6.1.4.4)
141
+ actionpack (= 6.1.4.4)
142
+ activesupport (= 6.1.4.4)
144
143
  method_source
145
- rake (>= 0.8.7)
146
- thor (>= 0.20.3, < 2.0)
147
- rainbow (3.0.0)
148
- rake (13.0.1)
149
- regexp_parser (1.8.2)
144
+ rake (>= 0.13)
145
+ thor (~> 1.0)
146
+ rainbow (3.1.1)
147
+ rake (13.0.6)
148
+ regexp_parser (2.2.0)
150
149
  rexml (3.2.5)
151
150
  rspec (3.10.0)
152
151
  rspec-core (~> 3.10.0)
153
152
  rspec-expectations (~> 3.10.0)
154
153
  rspec-mocks (~> 3.10.0)
155
- rspec-core (3.10.0)
154
+ rspec-core (3.10.1)
156
155
  rspec-support (~> 3.10.0)
157
- rspec-expectations (3.10.0)
156
+ rspec-expectations (3.10.2)
158
157
  diff-lcs (>= 1.2.0, < 2.0)
159
158
  rspec-support (~> 3.10.0)
160
- rspec-mocks (3.10.0)
159
+ rspec-mocks (3.10.2)
161
160
  diff-lcs (>= 1.2.0, < 2.0)
162
161
  rspec-support (~> 3.10.0)
163
- rspec-support (3.10.0)
164
- rubocop (0.91.0)
162
+ rspec-support (3.10.3)
163
+ rubocop (1.5.2)
165
164
  parallel (~> 1.10)
166
- parser (>= 2.7.1.1)
165
+ parser (>= 2.7.1.5)
167
166
  rainbow (>= 2.2.2, < 4.0)
168
- regexp_parser (>= 1.7)
167
+ regexp_parser (>= 1.8, < 3.0)
169
168
  rexml
170
- rubocop-ast (>= 0.4.0, < 1.0)
169
+ rubocop-ast (>= 1.2.0, < 2.0)
171
170
  ruby-progressbar (~> 1.7)
172
171
  unicode-display_width (>= 1.4.0, < 2.0)
173
- rubocop-ast (0.8.0)
174
- parser (>= 2.7.1.5)
175
- rubocop-performance (1.8.1)
176
- rubocop (>= 0.87.0)
172
+ rubocop-ast (1.15.1)
173
+ parser (>= 3.0.1.1)
174
+ rubocop-performance (1.10.2)
175
+ rubocop (>= 0.90.0, < 2.0)
177
176
  rubocop-ast (>= 0.4.0)
178
- rubocop-rspec (1.44.1)
179
- rubocop (~> 0.87)
180
- rubocop-ast (>= 0.7.1)
181
- ruby-progressbar (1.10.1)
182
- simplecov (0.19.1)
177
+ rubocop-rspec (2.4.0)
178
+ rubocop (~> 1.0)
179
+ rubocop-ast (>= 1.1.0)
180
+ ruby-progressbar (1.11.0)
181
+ ruby2_keywords (0.0.5)
182
+ simplecov (0.21.2)
183
183
  docile (~> 1.1)
184
184
  simplecov-html (~> 0.11)
185
+ simplecov_json_formatter (~> 0.1)
185
186
  simplecov-html (0.12.3)
187
+ simplecov_json_formatter (0.1.3)
186
188
  sprockets (4.0.2)
187
189
  concurrent-ruby (~> 1.0)
188
190
  rack (> 1, < 3)
189
- sprockets-rails (3.2.2)
190
- actionpack (>= 4.0)
191
- activesupport (>= 4.0)
191
+ sprockets-rails (3.4.2)
192
+ actionpack (>= 5.2)
193
+ activesupport (>= 5.2)
192
194
  sprockets (>= 3.0.0)
193
- thor (1.0.1)
194
- thread_safe (0.3.6)
195
- tzinfo (1.2.7)
196
- thread_safe (~> 0.1)
197
- unicode-display_width (1.7.0)
198
- websocket-driver (0.7.3)
195
+ thor (1.2.1)
196
+ tzinfo (2.0.4)
197
+ concurrent-ruby (~> 1.0)
198
+ unicode-display_width (1.8.0)
199
+ websocket-driver (0.7.5)
199
200
  websocket-extensions (>= 0.1.0)
200
201
  websocket-extensions (0.1.5)
201
- zeitwerk (2.4.1)
202
+ zeitwerk (2.5.3)
202
203
 
203
204
  PLATFORMS
204
205
  ruby
@@ -213,10 +214,10 @@ DEPENDENCIES
213
214
  rails (~> 6)
214
215
  rake (~> 13.0)
215
216
  rspec (~> 3.0)
216
- rubocop (= 0.91.0)
217
- rubocop-performance (~> 1.8, >= 1.8.1)
218
- rubocop-rspec (~> 1.44, >= 1.44.1)
217
+ rubocop (= 1.5.2)
218
+ rubocop-performance
219
+ rubocop-rspec
219
220
  simplecov
220
221
 
221
222
  BUNDLED WITH
222
- 2.1.4
223
+ 2.2.28
data/docs/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # GraphqlRails
2
2
 
3
- [![Build Status](https://travis-ci.org/samesystem/graphql_rails.svg?branch=master)](https://travis-ci.org/samesystem/graphql_rails)
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
 
@@ -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` type
31
- * attributes which ends with `?` has `Boolean` type
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
- available types are:
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.
@@ -73,14 +73,15 @@ end
73
73
 
74
74
  This will generate `userDetails` field on GraphQL side.
75
75
 
76
- ## _query_ and _mutation_
76
+ ## _query_ and _mutation_ & _subscription_
77
77
 
78
- in case you want to have non-CRUD controller with custom actions you can define your own `query`/`mutation` actions like this:
78
+ in case you want to have non-CRUD controller with custom actions you can define your own `query`/`mutation`/`subscription` actions like this:
79
79
 
80
80
  ```ruby
81
81
  MyGraphqlSchema = GraphqlRails::Router.draw do
82
82
  mutation :logIn, to: 'sessions#login'
83
- query :me, to 'users#current_user'
83
+ query :me, to: 'users#current_user'
84
+ subscribtion :new_message, to: 'messages#created'
84
85
  end
85
86
  ```
86
87