graphql_rails 0.8.0 → 1.2.2

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 (75) hide show
  1. checksums.yaml +4 -4
  2. data/.hound.yml +1 -0
  3. data/.rubocop.yml +3 -3
  4. data/.ruby-version +1 -1
  5. data/.travis.yml +2 -2
  6. data/CHANGELOG.md +31 -0
  7. data/Gemfile +3 -2
  8. data/Gemfile.lock +147 -124
  9. data/docs/README.md +24 -8
  10. data/docs/_sidebar.md +3 -0
  11. data/docs/components/controller.md +194 -21
  12. data/docs/components/model.md +193 -5
  13. data/docs/components/routes.md +28 -0
  14. data/docs/getting_started/quick_start.md +10 -3
  15. data/docs/index.html +1 -1
  16. data/docs/other_tools/query_runner.md +49 -0
  17. data/docs/other_tools/schema_dump.md +29 -0
  18. data/docs/testing/testing.md +3 -1
  19. data/graphql_rails.gemspec +5 -5
  20. data/lib/generators/graphql_rails/install_generator.rb +50 -0
  21. data/lib/generators/graphql_rails/templates/example_users_controller.erb +19 -0
  22. data/lib/generators/graphql_rails/templates/graphql_application_controller.erb +8 -0
  23. data/lib/generators/graphql_rails/templates/graphql_controller.erb +20 -0
  24. data/lib/generators/graphql_rails/templates/graphql_router.erb +19 -0
  25. data/lib/generators/graphql_rails/templates/graphql_router_spec.erb +21 -0
  26. data/lib/graphql_rails.rb +2 -0
  27. data/lib/graphql_rails/attributes/attributable.rb +20 -21
  28. data/lib/graphql_rails/attributes/attribute.rb +41 -4
  29. data/lib/graphql_rails/attributes/attribute_name_parser.rb +4 -4
  30. data/lib/graphql_rails/attributes/input_attribute.rb +24 -10
  31. data/lib/graphql_rails/attributes/input_type_parser.rb +24 -46
  32. data/lib/graphql_rails/attributes/type_parseable.rb +132 -0
  33. data/lib/graphql_rails/attributes/type_parser.rb +58 -54
  34. data/lib/graphql_rails/concerns/service.rb +19 -0
  35. data/lib/graphql_rails/controller.rb +26 -22
  36. data/lib/graphql_rails/controller/action.rb +12 -67
  37. data/lib/graphql_rails/controller/action_configuration.rb +70 -34
  38. data/lib/graphql_rails/controller/build_controller_action_resolver.rb +52 -0
  39. data/lib/graphql_rails/controller/build_controller_action_resolver/controller_action_resolver.rb +28 -0
  40. data/lib/graphql_rails/controller/configuration.rb +56 -5
  41. data/lib/graphql_rails/controller/log_controller_action.rb +11 -6
  42. data/lib/graphql_rails/controller/request.rb +29 -8
  43. data/lib/graphql_rails/controller/request/format_errors.rb +58 -0
  44. data/lib/graphql_rails/decorator/relation_decorator.rb +1 -5
  45. data/lib/graphql_rails/errors/custom_execution_error.rb +22 -0
  46. data/lib/graphql_rails/errors/execution_error.rb +6 -7
  47. data/lib/graphql_rails/errors/system_error.rb +14 -0
  48. data/lib/graphql_rails/errors/validation_error.rb +1 -5
  49. data/lib/graphql_rails/input_configurable.rb +47 -0
  50. data/lib/graphql_rails/model.rb +19 -4
  51. data/lib/graphql_rails/model/add_fields_to_graphql_type.rb +45 -0
  52. data/lib/graphql_rails/model/build_connection_type.rb +52 -0
  53. data/lib/graphql_rails/model/{configuration → build_connection_type}/count_items.rb +5 -5
  54. data/lib/graphql_rails/model/build_enum_type.rb +39 -10
  55. data/lib/graphql_rails/model/build_graphql_input_type.rb +8 -4
  56. data/lib/graphql_rails/model/call_graphql_model_method.rb +72 -0
  57. data/lib/graphql_rails/model/configurable.rb +6 -2
  58. data/lib/graphql_rails/model/configuration.rb +11 -10
  59. data/lib/graphql_rails/model/find_or_build_graphql_type.rb +64 -0
  60. data/lib/graphql_rails/model/find_or_build_graphql_type_class.rb +46 -0
  61. data/lib/graphql_rails/model/input.rb +10 -6
  62. data/lib/graphql_rails/query_runner.rb +68 -0
  63. data/lib/graphql_rails/railtie.rb +10 -0
  64. data/lib/graphql_rails/router.rb +40 -13
  65. data/lib/graphql_rails/router/resource_routes_builder.rb +10 -9
  66. data/lib/graphql_rails/router/route.rb +21 -6
  67. data/lib/graphql_rails/router/schema_builder.rb +30 -11
  68. data/lib/graphql_rails/rspec_controller_helpers.rb +6 -4
  69. data/lib/graphql_rails/tasks/dump_graphql_schema.rb +57 -0
  70. data/lib/graphql_rails/tasks/schema.rake +14 -0
  71. data/lib/graphql_rails/version.rb +1 -1
  72. metadata +48 -21
  73. data/lib/graphql_rails/controller/controller_function.rb +0 -50
  74. data/lib/graphql_rails/controller/format_results.rb +0 -36
  75. data/lib/graphql_rails/model/build_graphql_type.rb +0 -37
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GraphqlRails
4
+ # Generates graphql schema dump files
5
+ class DumpGraphqlSchema
6
+ require 'graphql_rails/errors/error'
7
+
8
+ class MissingGraphqlRouterError < GraphqlRails::Error; end
9
+
10
+ attr_reader :name
11
+
12
+ def self.call(*args)
13
+ new(*args).call
14
+ end
15
+
16
+ def initialize(name:)
17
+ @name = name
18
+ end
19
+
20
+ def call
21
+ validate
22
+ File.write(schema_path, schema.to_definition)
23
+ end
24
+
25
+ private
26
+
27
+ def validate
28
+ return if router
29
+
30
+ error_message = \
31
+ 'GraphqlRouter is missing. ' \
32
+ 'Run `rails g graphql_rails:install` to build it'
33
+ raise MissingGraphqlRouterError, error_message
34
+ end
35
+
36
+ def router
37
+ @router ||= '::GraphqlRouter'.safe_constantize
38
+ end
39
+
40
+ def schema
41
+ @schema ||= ::GraphqlRouter.graphql_schema(name.presence)
42
+ end
43
+
44
+ def schema_path
45
+ ENV['GRAPHQL_SCHEMA_DUMP_PATH'] || default_schema_path
46
+ end
47
+
48
+ def default_schema_path
49
+ schema_folder_path = Rails.root.join('spec', 'fixtures')
50
+
51
+ FileUtils.mkdir_p(schema_folder_path)
52
+ file_name = name.present? ? "graphql_#{name}_schema.graphql" : 'graphql_schema.graphql'
53
+
54
+ schema_folder_path.join(file_name)
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'graphql_rails/tasks/dump_graphql_schema'
4
+
5
+ namespace :graphql_rails do
6
+ namespace :schema do
7
+ desc 'Dump GraphQL schema'
8
+ task(:dump, %i[name] => :environment) do |_, args|
9
+ default_name = ENV.fetch('SCHEMA_GROUP_NAME', '')
10
+ args.with_defaults(name: default_name)
11
+ GraphqlRails::DumpGraphqlSchema.call(name: args.name)
12
+ end
13
+ end
14
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GraphqlRails
4
- VERSION = '0.8.0'
4
+ VERSION = '1.2.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Povilas Jurčys
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-03 00:00:00.000000000 Z
11
+ date: 2021-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql
@@ -16,14 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1'
19
+ version: '1.12'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.12.4
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
27
  - - "~>"
25
28
  - !ruby/object:Gem::Version
26
- version: '1'
29
+ version: '1.12'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.12.4
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: activesupport
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -44,28 +50,28 @@ dependencies:
44
50
  requirements:
45
51
  - - "~>"
46
52
  - !ruby/object:Gem::Version
47
- version: '1.16'
53
+ version: '2'
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
51
57
  requirements:
52
58
  - - "~>"
53
59
  - !ruby/object:Gem::Version
54
- version: '1.16'
60
+ version: '2'
55
61
  - !ruby/object:Gem::Dependency
56
62
  name: rake
57
63
  requirement: !ruby/object:Gem::Requirement
58
64
  requirements:
59
65
  - - "~>"
60
66
  - !ruby/object:Gem::Version
61
- version: '10.0'
67
+ version: '13.0'
62
68
  type: :development
63
69
  prerelease: false
64
70
  version_requirements: !ruby/object:Gem::Requirement
65
71
  requirements:
66
72
  - - "~>"
67
73
  - !ruby/object:Gem::Version
68
- version: '10.0'
74
+ version: '13.0'
69
75
  - !ruby/object:Gem::Dependency
70
76
  name: rspec
71
77
  requirement: !ruby/object:Gem::Requirement
@@ -114,15 +120,15 @@ dependencies:
114
120
  requirements:
115
121
  - - "~>"
116
122
  - !ruby/object:Gem::Version
117
- version: '5'
123
+ version: '6'
118
124
  type: :development
119
125
  prerelease: false
120
126
  version_requirements: !ruby/object:Gem::Requirement
121
127
  requirements:
122
128
  - - "~>"
123
129
  - !ruby/object:Gem::Version
124
- version: '5'
125
- description:
130
+ version: '6'
131
+ description:
126
132
  email:
127
133
  - po.jurcys@gmail.com
128
134
  executables: []
@@ -154,8 +160,16 @@ files:
154
160
  - docs/getting_started/setup.md
155
161
  - docs/index.html
156
162
  - docs/logging_and_monitoring/logging_and_monitoring.md
163
+ - docs/other_tools/query_runner.md
164
+ - docs/other_tools/schema_dump.md
157
165
  - docs/testing/testing.md
158
166
  - graphql_rails.gemspec
167
+ - lib/generators/graphql_rails/install_generator.rb
168
+ - lib/generators/graphql_rails/templates/example_users_controller.erb
169
+ - lib/generators/graphql_rails/templates/graphql_application_controller.erb
170
+ - lib/generators/graphql_rails/templates/graphql_controller.erb
171
+ - lib/generators/graphql_rails/templates/graphql_router.erb
172
+ - lib/generators/graphql_rails/templates/graphql_router_spec.erb
159
173
  - lib/graphql_rails.rb
160
174
  - lib/graphql_rails/attributes.rb
161
175
  - lib/graphql_rails/attributes/attributable.rb
@@ -164,33 +178,45 @@ files:
164
178
  - lib/graphql_rails/attributes/input_attribute.rb
165
179
  - lib/graphql_rails/attributes/input_type_parser.rb
166
180
  - lib/graphql_rails/attributes/type_name_info.rb
181
+ - lib/graphql_rails/attributes/type_parseable.rb
167
182
  - lib/graphql_rails/attributes/type_parser.rb
183
+ - lib/graphql_rails/concerns/service.rb
168
184
  - lib/graphql_rails/controller.rb
169
185
  - lib/graphql_rails/controller/action.rb
170
186
  - lib/graphql_rails/controller/action_configuration.rb
171
187
  - lib/graphql_rails/controller/action_hook.rb
172
188
  - lib/graphql_rails/controller/action_hooks_runner.rb
189
+ - lib/graphql_rails/controller/build_controller_action_resolver.rb
190
+ - lib/graphql_rails/controller/build_controller_action_resolver/controller_action_resolver.rb
173
191
  - lib/graphql_rails/controller/configuration.rb
174
- - lib/graphql_rails/controller/controller_function.rb
175
- - lib/graphql_rails/controller/format_results.rb
176
192
  - lib/graphql_rails/controller/log_controller_action.rb
177
193
  - lib/graphql_rails/controller/request.rb
194
+ - lib/graphql_rails/controller/request/format_errors.rb
178
195
  - lib/graphql_rails/decorator.rb
179
196
  - lib/graphql_rails/decorator/relation_decorator.rb
197
+ - lib/graphql_rails/errors/custom_execution_error.rb
180
198
  - lib/graphql_rails/errors/error.rb
181
199
  - lib/graphql_rails/errors/execution_error.rb
200
+ - lib/graphql_rails/errors/system_error.rb
182
201
  - lib/graphql_rails/errors/validation_error.rb
202
+ - lib/graphql_rails/input_configurable.rb
183
203
  - lib/graphql_rails/integrations.rb
184
204
  - lib/graphql_rails/integrations/lograge.rb
185
205
  - lib/graphql_rails/integrations/sentry.rb
186
206
  - lib/graphql_rails/model.rb
207
+ - lib/graphql_rails/model/add_fields_to_graphql_type.rb
208
+ - lib/graphql_rails/model/build_connection_type.rb
209
+ - lib/graphql_rails/model/build_connection_type/count_items.rb
187
210
  - lib/graphql_rails/model/build_enum_type.rb
188
211
  - lib/graphql_rails/model/build_graphql_input_type.rb
189
- - lib/graphql_rails/model/build_graphql_type.rb
212
+ - lib/graphql_rails/model/call_graphql_model_method.rb
190
213
  - lib/graphql_rails/model/configurable.rb
191
214
  - lib/graphql_rails/model/configuration.rb
192
- - lib/graphql_rails/model/configuration/count_items.rb
215
+ - lib/graphql_rails/model/find_or_build_graphql_type.rb
216
+ - lib/graphql_rails/model/find_or_build_graphql_type_class.rb
193
217
  - lib/graphql_rails/model/input.rb
218
+ - lib/graphql_rails/query_runner.rb
219
+ - lib/graphql_rails/railtie.rb
194
220
  - lib/graphql_rails/router.rb
195
221
  - lib/graphql_rails/router/mutation_route.rb
196
222
  - lib/graphql_rails/router/plain_cursor_encoder.rb
@@ -199,12 +225,14 @@ files:
199
225
  - lib/graphql_rails/router/route.rb
200
226
  - lib/graphql_rails/router/schema_builder.rb
201
227
  - lib/graphql_rails/rspec_controller_helpers.rb
228
+ - lib/graphql_rails/tasks/dump_graphql_schema.rb
229
+ - lib/graphql_rails/tasks/schema.rake
202
230
  - lib/graphql_rails/version.rb
203
231
  homepage: https://github.com/samesystem/graphql_rails
204
232
  licenses:
205
233
  - MIT
206
234
  metadata: {}
207
- post_install_message:
235
+ post_install_message:
208
236
  rdoc_options: []
209
237
  require_paths:
210
238
  - lib
@@ -219,9 +247,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
219
247
  - !ruby/object:Gem::Version
220
248
  version: '0'
221
249
  requirements: []
222
- rubyforge_project:
223
- rubygems_version: 2.7.7
224
- signing_key:
250
+ rubygems_version: 3.1.2
251
+ signing_key:
225
252
  specification_version: 4
226
- summary: GraphQL server and client for rails
253
+ summary: Rails style structure for GraphQL API.
227
254
  test_files: []
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'graphql_rails/controller/action'
4
- require_relative 'request'
5
- require_relative 'action'
6
-
7
- module GraphqlRails
8
- class Controller
9
- # graphql resolver which redirects actions to appropriate controller and controller action
10
- class ControllerFunction < GraphQL::Function
11
- # accepts path of given format "controller_name#action"
12
- attr_reader :type
13
-
14
- def initialize(controller:, action_name:, type:)
15
- @controller = controller
16
- @action_name = action_name
17
- @type = type
18
- end
19
-
20
- def self.from_route(route)
21
- action = Action.new(route)
22
-
23
- action_function_class(action).new(
24
- controller: action.controller,
25
- action_name: action.name,
26
- type: action.return_type
27
- )
28
- end
29
-
30
- def self.action_function_class(action)
31
- Class.new(self) do
32
- description(action.description)
33
-
34
- action.arguments.each do |attribute|
35
- argument(*attribute.function_argument_args)
36
- end
37
- end
38
- end
39
-
40
- def call(object, inputs, ctx)
41
- request = Request.new(object, inputs, ctx)
42
- controller.new(request).call(action_name)
43
- end
44
-
45
- private
46
-
47
- attr_reader :controller, :action_name
48
- end
49
- end
50
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module GraphqlRails
4
- class Controller
5
- # Convers raw controller results in to graphql-friendly format
6
- class FormatResults
7
- def initialize(original_result, action_config:, params:, graphql_context:)
8
- @original_result = original_result
9
- @action_config = action_config
10
- @controller_params = params
11
- @graphql_context = graphql_context
12
- end
13
-
14
- def call
15
- if action_config.paginated? && original_result
16
- paginated_result
17
- else
18
- original_result
19
- end
20
- end
21
-
22
- private
23
-
24
- attr_reader :original_result, :action_config, :controller_params, :graphql_context
25
-
26
- def paginated_result
27
- pagination_params = controller_params.slice(:first, :last, :before, :after)
28
- pagination_options = action_config.pagination_options.merge(context: graphql_context)
29
-
30
- GraphQL::Relay::BaseConnection
31
- .connection_for_nodes(original_result)
32
- .new(original_result, pagination_params, pagination_options)
33
- end
34
- end
35
- end
36
- end
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module GraphqlRails
4
- module Model
5
- # stores information about model specific config, like attributes and types
6
- class BuildGraphqlType
7
- def self.call(*args)
8
- new(*args).call
9
- end
10
-
11
- def initialize(name:, description: nil, attributes:)
12
- @name = name
13
- @attributes = attributes
14
- @description = description
15
- end
16
-
17
- def call
18
- type_name = name
19
- type_description = description
20
- type_attributes = attributes
21
-
22
- GraphQL::ObjectType.define do
23
- name(type_name)
24
- description(type_description)
25
-
26
- type_attributes.each_value do |attribute|
27
- field(*attribute.field_args)
28
- end
29
- end
30
- end
31
-
32
- private
33
-
34
- attr_reader :model_configuration, :attributes, :name, :description
35
- end
36
- end
37
- end