graphql_rails 2.2.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +3 -2
  3. data/.ruby-version +1 -1
  4. data/CHANGELOG.md +16 -0
  5. data/Gemfile.lock +17 -17
  6. data/docs/README.md +23 -45
  7. data/docs/_sidebar.md +0 -1
  8. data/docs/components/controller.md +15 -1
  9. data/docs/components/decorator.md +1 -1
  10. data/docs/components/model.md +100 -5
  11. data/docs/components/routes.md +61 -15
  12. data/graphql_rails.gemspec +1 -1
  13. data/lib/generators/graphql_rails/templates/graphql_controller.erb +1 -1
  14. data/lib/graphql_rails/attributes/attribute.rb +16 -14
  15. data/lib/graphql_rails/attributes/attribute_configurable.rb +24 -0
  16. data/lib/graphql_rails/attributes/attribute_name_parser.rb +4 -4
  17. data/lib/graphql_rails/attributes/input_attribute.rb +19 -2
  18. data/lib/graphql_rails/attributes/type_parseable.rb +4 -5
  19. data/lib/graphql_rails/controller/action_configuration.rb +1 -1
  20. data/lib/graphql_rails/controller/build_controller_action_resolver.rb +2 -0
  21. data/lib/graphql_rails/controller/configuration.rb +1 -1
  22. data/lib/graphql_rails/controller/request/format_errors.rb +1 -1
  23. data/lib/graphql_rails/controller/request.rb +3 -2
  24. data/lib/graphql_rails/controller.rb +1 -1
  25. data/lib/graphql_rails/decorator/relation_decorator.rb +24 -20
  26. data/lib/graphql_rails/decorator.rb +12 -4
  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/errors/system_error.rb +11 -1
  30. data/lib/graphql_rails/errors/validation_error.rb +14 -1
  31. data/lib/graphql_rails/model/find_or_build_graphql_input_type.rb +28 -0
  32. data/lib/graphql_rails/model/find_or_build_graphql_type.rb +14 -5
  33. data/lib/graphql_rails/model/find_or_build_graphql_type_class.rb +4 -3
  34. data/lib/graphql_rails/model/input.rb +3 -3
  35. data/lib/graphql_rails/router/build_schema_action_type.rb +112 -0
  36. data/lib/graphql_rails/router/event_route.rb +52 -0
  37. data/lib/graphql_rails/router/mutation_route.rb +1 -1
  38. data/lib/graphql_rails/router/query_route.rb +1 -1
  39. data/lib/graphql_rails/router/resource_routes_builder.rb +0 -8
  40. data/lib/graphql_rails/router/route.rb +4 -3
  41. data/lib/graphql_rails/router/schema_builder.rb +18 -26
  42. data/lib/graphql_rails/router.rb +32 -16
  43. data/lib/graphql_rails/rspec_controller_helpers.rb +3 -1
  44. data/lib/graphql_rails/types/hidable_by_group.rb +23 -3
  45. data/lib/graphql_rails/types/input_object_type.rb +16 -0
  46. data/lib/graphql_rails/version.rb +1 -1
  47. metadata +11 -16
  48. data/docs/getting_started/quick_start.md +0 -62
  49. data/lib/graphql_rails/model/build_graphql_input_type.rb +0 -43
  50. data/lib/graphql_rails/router/subscription_route.rb +0 -22
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'route'
4
+
5
+ module GraphqlRails
6
+ class Router
7
+ # stores subscription type graphql action info
8
+ class EventRoute
9
+ attr_reader :name, :module_name, :subscription_class, :groups, :scope_names
10
+
11
+ def initialize(name, subscription_class: nil, groups: nil, scope_names: [], **options)
12
+ @name = name.to_s.camelize(:lower)
13
+ @module_name = options[:module].to_s
14
+ @groups = groups
15
+ @subscription_class = subscription_class
16
+ @scope_names = scope_names
17
+ end
18
+
19
+ def show_in_group?(group_name)
20
+ return true if groups.nil? || groups.empty?
21
+
22
+ groups.include?(group_name&.to_sym)
23
+ end
24
+
25
+ def field_options
26
+ { subscription: subscription }
27
+ end
28
+
29
+ def subscription
30
+ if subscription_class.present?
31
+ subscription_class.is_a?(String) ? Object.const_get(subscription_class) : subscription_class
32
+ else
33
+ klass_name = ['subscriptions/', name.underscore, 'subscription'].join('_').camelize
34
+
35
+ Object.const_get(klass_name)
36
+ end
37
+ end
38
+
39
+ def mutation?
40
+ false
41
+ end
42
+
43
+ def query?
44
+ false
45
+ end
46
+
47
+ def event?
48
+ true
49
+ end
50
+ end
51
+ end
52
+ end
@@ -14,7 +14,7 @@ module GraphqlRails
14
14
  true
15
15
  end
16
16
 
17
- def subscription?
17
+ def event?
18
18
  false
19
19
  end
20
20
  end
@@ -14,7 +14,7 @@ module GraphqlRails
14
14
  false
15
15
  end
16
16
 
17
- def subscription?
17
+ def event?
18
18
  false
19
19
  end
20
20
  end
@@ -28,10 +28,6 @@ module GraphqlRails
28
28
  routes << build_mutation(*args, **kwargs)
29
29
  end
30
30
 
31
- def subscription(*args, **kwargs)
32
- routes << build_subscription(*args, **kwargs)
33
- end
34
-
35
31
  private
36
32
 
37
33
  attr_reader :autogenerated_action_names, :name, :options
@@ -66,10 +62,6 @@ module GraphqlRails
66
62
  build_route(QueryRoute, *args, **kwargs)
67
63
  end
68
64
 
69
- def build_subscription(*args, **kwargs)
70
- build_route(SubscriptionRoute, *args, **kwargs)
71
- end
72
-
73
65
  # rubocop:disable Metrics/ParameterLists
74
66
  def build_route(builder, action, prefix: action, suffix: false, on: :member, **custom_options)
75
67
  if suffix == true
@@ -6,15 +6,16 @@ module GraphqlRails
6
6
  class Router
7
7
  # Generic class for any type graphql action. Should not be used directly
8
8
  class Route
9
- attr_reader :name, :module_name, :on, :relative_path, :groups
9
+ attr_reader :name, :module_name, :on, :relative_path, :groups, :scope_names
10
10
 
11
- def initialize(name, to: '', on:, groups: nil, **options)
11
+ def initialize(name, on:, to: '', groups: nil, scope_names: [], **options) # rubocop:disable Metrics/ParameterLists
12
12
  @name = name.to_s.camelize(:lower)
13
13
  @module_name = options[:module].to_s
14
14
  @function = options[:function]
15
15
  @groups = groups
16
16
  @relative_path = to
17
17
  @on = on.to_sym
18
+ @scope_names = scope_names
18
19
  end
19
20
 
20
21
  def path
@@ -37,7 +38,7 @@ module GraphqlRails
37
38
  if function
38
39
  { function: function }
39
40
  else
40
- { resolver: resolver }
41
+ { resolver: resolver, extras: [:lookahead] }
41
42
  end
42
43
  end
43
44
 
@@ -5,13 +5,14 @@ module GraphqlRails
5
5
  # builds GraphQL::Schema based on previously defined grahiti data
6
6
  class SchemaBuilder
7
7
  require_relative './plain_cursor_encoder'
8
+ require_relative './build_schema_action_type'
8
9
 
9
- attr_reader :queries, :mutations, :subscriptions, :raw_actions
10
+ attr_reader :queries, :mutations, :events, :raw_actions
10
11
 
11
- def initialize(queries:, mutations:, subscriptions:, raw_actions:, group: nil)
12
+ def initialize(queries:, mutations:, events:, raw_actions:, group: nil)
12
13
  @queries = queries
13
14
  @mutations = mutations
14
- @subscriptions = subscriptions
15
+ @events = events
15
16
  @raw_actions = raw_actions
16
17
  @group = group
17
18
  end
@@ -19,26 +20,31 @@ module GraphqlRails
19
20
  def call
20
21
  query_type = build_group_type('Query', queries)
21
22
  mutation_type = build_group_type('Mutation', mutations)
22
- subscription_type = build_group_type('Subscription', subscriptions)
23
- raw = raw_actions
23
+ subscription_type = build_group_type('Subscription', events)
24
24
 
25
+ define_schema_class(query_type, mutation_type, subscription_type, raw_actions)
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :group
31
+
32
+ # rubocop:disable Metrics/MethodLength
33
+ def define_schema_class(query_type, mutation_type, subscription_type, raw)
25
34
  Class.new(GraphQL::Schema) do
26
35
  connections.add(
27
36
  GraphqlRails::Decorator::RelationDecorator,
28
37
  GraphQL::Pagination::ActiveRecordRelationConnection
29
38
  )
30
39
  cursor_encoder(Router::PlainCursorEncoder)
31
- raw.each { |action| send(action[:name], *action[:args], &action[:block]) }
40
+ raw.each { |action| send(action[:name], *action[:args], **action[:kwargs], &action[:block]) }
32
41
 
33
42
  query(query_type) if query_type
34
43
  mutation(mutation_type) if mutation_type
35
44
  subscription(subscription_type) if subscription_type
36
45
  end
37
46
  end
38
-
39
- private
40
-
41
- attr_reader :group
47
+ # rubocop:enable Metrics/MethodLength
42
48
 
43
49
  def build_group_type(type_name, routes)
44
50
  group_name = group
@@ -49,23 +55,9 @@ module GraphqlRails
49
55
  .uniq(&:name)
50
56
  .reverse
51
57
 
52
- return if group_routes.empty?
53
-
54
- build_type(type_name, group_routes)
55
- end
58
+ return if group_routes.empty? && type_name != 'Query'
56
59
 
57
- def build_type(type_name, group_routes)
58
- Class.new(GraphQL::Schema::Object) do
59
- graphql_name(type_name)
60
-
61
- group_routes.each do |route|
62
- field(*route.name, **route.field_options)
63
- end
64
-
65
- def self.inspect
66
- "#{GraphQL::Schema::Object}(#{graphql_name})"
67
- end
68
- end
60
+ BuildSchemaActionType.call(type_name: type_name, routes: group_routes)
69
61
  end
70
62
  end
71
63
  end
@@ -5,7 +5,7 @@ require 'active_support/core_ext/string/inflections'
5
5
  require 'graphql_rails/router/schema_builder'
6
6
  require 'graphql_rails/router/mutation_route'
7
7
  require 'graphql_rails/router/query_route'
8
- require 'graphql_rails/router/subscription_route'
8
+ require 'graphql_rails/router/event_route'
9
9
  require 'graphql_rails/router/resource_routes_builder'
10
10
 
11
11
  module GraphqlRails
@@ -21,9 +21,10 @@ module GraphqlRails
21
21
  end
22
22
  end
23
23
 
24
- attr_reader :routes, :namespace_name, :raw_graphql_actions
24
+ attr_reader :routes, :namespace_name, :raw_graphql_actions, :scope_names
25
25
 
26
- def initialize(module_name: '', group_names: [])
26
+ def initialize(module_name: '', group_names: [], scope_names: [])
27
+ @scope_names = scope_names
27
28
  @module_name = module_name
28
29
  @group_names = group_names
29
30
  @routes ||= Set.new
@@ -37,13 +38,16 @@ module GraphqlRails
37
38
  routes.merge(scoped_router.routes)
38
39
  end
39
40
 
40
- def scope(**options, &block)
41
- full_module_name = [module_name, options[:module]].reject(&:empty?).join('/')
42
- scoped_router = router_with(module_name: full_module_name)
41
+ def scope(new_scope_name = nil, **options, &block)
42
+ scoped_router = router_with_scope_params(new_scope_name, **options)
43
43
  scoped_router.instance_eval(&block)
44
44
  routes.merge(scoped_router.routes)
45
45
  end
46
46
 
47
+ def namespace(namespace_name, &block)
48
+ scope(path: namespace_name, module: namespace_name, &block)
49
+ end
50
+
47
51
  def resources(name, **options, &block)
48
52
  builder_options = full_route_options(options)
49
53
  routes_builder = ResourceRoutesBuilder.new(name, **builder_options)
@@ -59,13 +63,13 @@ module GraphqlRails
59
63
  routes << build_route(MutationRoute, name, **options)
60
64
  end
61
65
 
62
- def subscription(name, **options)
63
- routes << build_route(SubscriptionRoute, name, **options)
66
+ def event(name, **options)
67
+ routes << build_route(EventRoute, name, **options)
64
68
  end
65
69
 
66
70
  RAW_ACTION_NAMES.each do |action_name|
67
- define_method(action_name) do |*args, &block|
68
- add_raw_action(action_name, *args, &block)
71
+ define_method(action_name) do |*args, **kwargs, &block|
72
+ add_raw_action(action_name, *args, **kwargs, &block)
69
73
  end
70
74
  end
71
75
 
@@ -73,7 +77,7 @@ module GraphqlRails
73
77
  @graphql_schema[group&.to_sym] ||= SchemaBuilder.new(
74
78
  queries: routes.select(&:query?),
75
79
  mutations: routes.select(&:mutation?),
76
- subscriptions: routes.select(&:subscription?),
80
+ events: routes.select(&:event?),
77
81
  raw_actions: raw_graphql_actions,
78
82
  group: group
79
83
  ).call
@@ -87,15 +91,27 @@ module GraphqlRails
87
91
 
88
92
  attr_reader :module_name, :group_names
89
93
 
94
+ def router_with_scope_params(new_scope_name, **options)
95
+ new_scope_name ||= options[:path]
96
+
97
+ full_module_name = [module_name, options[:module]].select(&:present?).join('/')
98
+ full_scope_names = [*scope_names, new_scope_name].select(&:present?)
99
+
100
+ router_with(module_name: full_module_name, scope_names: full_scope_names)
101
+ end
102
+
90
103
  def router_with(new_router_options = {})
91
- default_options = { module_name: module_name, group_names: group_names }
92
- full_options = default_options.merge(new_router_options)
104
+ full_options = default_router_options.merge(new_router_options)
93
105
 
94
106
  self.class.new(**full_options)
95
107
  end
96
108
 
97
- def add_raw_action(name, *args, &block)
98
- raw_graphql_actions << { name: name, args: args, block: block }
109
+ def default_router_options
110
+ { module_name: module_name, group_names: group_names, scope_names: scope_names }
111
+ end
112
+
113
+ def add_raw_action(name, *args, **kwargs, &block)
114
+ raw_graphql_actions << { name: name, args: args, kwargs: kwargs, block: block }
99
115
  end
100
116
 
101
117
  def build_route(route_builder, name, **options)
@@ -111,7 +127,7 @@ module GraphqlRails
111
127
  end
112
128
 
113
129
  def default_route_options
114
- { module: module_name, on: :member }
130
+ { module: module_name, on: :member, scope_names: scope_names }
115
131
  end
116
132
  end
117
133
  end
@@ -95,7 +95,9 @@ module GraphqlRails
95
95
  # controller request object more suitable for testing
96
96
  class Request < GraphqlRails::Controller::Request
97
97
  def initialize(params, context)
98
- super(nil, params, context)
98
+ inputs = params || {}
99
+ inputs = inputs.merge(lookahead: ::GraphQL::Execution::Lookahead::NullLookahead.new)
100
+ super(nil, inputs, context)
99
101
  end
100
102
  end
101
103
 
@@ -6,10 +6,11 @@ module GraphqlRails
6
6
  module Types
7
7
  # Add visibility option based on groups
8
8
  module HidableByGroup
9
- def initialize(*args, groups: [], **kwargs, &block)
9
+ def initialize(*args, groups: [], hidden_in_groups: [], **kwargs, &block)
10
10
  super(*args, **kwargs, &block)
11
11
 
12
- @groups = groups.map(&:to_s)
12
+ @hidden_in_groups = hidden_in_groups.map(&:to_s)
13
+ @groups = groups.map(&:to_s) - @hidden_in_groups
13
14
  end
14
15
 
15
16
  def visible?(context)
@@ -22,10 +23,29 @@ module GraphqlRails
22
23
  @groups
23
24
  end
24
25
 
26
+ def hidden_in_groups
27
+ @hidden_in_groups
28
+ end
29
+
25
30
  def visible_in_context_group?(context)
31
+ group = context_graphql_group(context)
32
+
33
+ return true if no_visibility_configuration?(group)
34
+ return groups.include?(group) unless groups.empty?
35
+
36
+ !hidden_in_groups.include?(group)
37
+ end
38
+
39
+ def no_visibility_configuration?(group)
40
+ return true if group.nil?
41
+
42
+ groups.empty? && hidden_in_groups.empty?
43
+ end
44
+
45
+ def context_graphql_group(context)
26
46
  group = context[:graphql_group] || context['graphql_group']
27
47
 
28
- group.nil? || groups.empty? || groups.include?(group.to_s)
48
+ group.nil? ? nil : group.to_s
29
49
  end
30
50
  end
31
51
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'graphql_rails/types/argument_type'
4
+
5
+ module GraphqlRails
6
+ module Types
7
+ # Base graphql type class for all GraphqlRails models
8
+ class InputObjectType < GraphQL::Schema::InputObject
9
+ argument_class(GraphqlRails::Types::ArgumentType)
10
+
11
+ def self.inspect
12
+ "#{GraphQL::Schema::InputObject}(#{graphql_name})"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GraphqlRails
4
- VERSION = '2.2.0'
4
+ VERSION = '2.4.0'
5
5
  end
metadata CHANGED
@@ -1,35 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Povilas Jurčys
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-25 00:00:00.000000000 Z
11
+ date: 2023-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.12'
20
- - - ">="
17
+ - - '='
21
18
  - !ruby/object:Gem::Version
22
- version: 1.12.4
19
+ version: 2.0.21
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: '1.12'
30
- - - ">="
24
+ - - '='
31
25
  - !ruby/object:Gem::Version
32
- version: 1.12.4
26
+ version: 2.0.21
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: activesupport
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -156,7 +150,6 @@ files:
156
150
  - docs/components/decorator.md
157
151
  - docs/components/model.md
158
152
  - docs/components/routes.md
159
- - docs/getting_started/quick_start.md
160
153
  - docs/getting_started/setup.md
161
154
  - docs/index.html
162
155
  - docs/logging_and_monitoring/logging_and_monitoring.md
@@ -210,23 +203,24 @@ files:
210
203
  - lib/graphql_rails/model/build_connection_type.rb
211
204
  - lib/graphql_rails/model/build_connection_type/count_items.rb
212
205
  - lib/graphql_rails/model/build_enum_type.rb
213
- - lib/graphql_rails/model/build_graphql_input_type.rb
214
206
  - lib/graphql_rails/model/call_graphql_model_method.rb
215
207
  - lib/graphql_rails/model/configurable.rb
216
208
  - lib/graphql_rails/model/configuration.rb
209
+ - lib/graphql_rails/model/find_or_build_graphql_input_type.rb
217
210
  - lib/graphql_rails/model/find_or_build_graphql_type.rb
218
211
  - lib/graphql_rails/model/find_or_build_graphql_type_class.rb
219
212
  - lib/graphql_rails/model/input.rb
220
213
  - lib/graphql_rails/query_runner.rb
221
214
  - lib/graphql_rails/railtie.rb
222
215
  - lib/graphql_rails/router.rb
216
+ - lib/graphql_rails/router/build_schema_action_type.rb
217
+ - lib/graphql_rails/router/event_route.rb
223
218
  - lib/graphql_rails/router/mutation_route.rb
224
219
  - lib/graphql_rails/router/plain_cursor_encoder.rb
225
220
  - lib/graphql_rails/router/query_route.rb
226
221
  - lib/graphql_rails/router/resource_routes_builder.rb
227
222
  - lib/graphql_rails/router/route.rb
228
223
  - lib/graphql_rails/router/schema_builder.rb
229
- - lib/graphql_rails/router/subscription_route.rb
230
224
  - lib/graphql_rails/rspec_controller_helpers.rb
231
225
  - lib/graphql_rails/tasks/dump_graphql_schema.rb
232
226
  - lib/graphql_rails/tasks/dump_graphql_schemas.rb
@@ -234,6 +228,7 @@ files:
234
228
  - lib/graphql_rails/types/argument_type.rb
235
229
  - lib/graphql_rails/types/field_type.rb
236
230
  - lib/graphql_rails/types/hidable_by_group.rb
231
+ - lib/graphql_rails/types/input_object_type.rb
237
232
  - lib/graphql_rails/types/object_type.rb
238
233
  - lib/graphql_rails/version.rb
239
234
  homepage: https://github.com/samesystem/graphql_rails
@@ -255,7 +250,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
255
250
  - !ruby/object:Gem::Version
256
251
  version: '0'
257
252
  requirements: []
258
- rubygems_version: 3.2.15
253
+ rubygems_version: 3.3.7
259
254
  signing_key:
260
255
  specification_version: 4
261
256
  summary: Rails style structure for GraphQL API.
@@ -1,62 +0,0 @@
1
- # Quick Start
2
-
3
- ## Generate initial code
4
-
5
- ```bash
6
- bundle exec rails g graphql_rails:install
7
- ```
8
-
9
- ## Define GraphQL schema as RoR routes
10
-
11
- ```ruby
12
- # config/graphql/routes.rb
13
- GraphqlRails::Router.draw do
14
- # will create createUser, updateUser, destroyUser mutations and user, users queries.
15
- # expects that UsersController class exist
16
- resources :users
17
-
18
- # if you want custom queries or mutation
19
- query 'searchLogs', to: 'logs#search' # redirects request to LogsController
20
- mutation 'changeUserPassword', to: 'users#change_password'
21
- end
22
- ```
23
-
24
- ## Define your Graphql model
25
-
26
- ```ruby
27
- class User # works with any class including ActiveRecord
28
- include GraphqlRails::Model
29
-
30
- graphql do |c|
31
- # most common attributes, like :id, :name, :title has default type, so you don't have to specify it (but you can!)
32
- c.attribute :id
33
-
34
- c.attribute :email, :string
35
- c.attribute :surname, :string
36
- end
37
- end
38
- ```
39
-
40
- ## Define controller
41
-
42
- ```ruby
43
- class UsersController < ApplicationGraphqlController
44
- # graphql requires to describe which attributes controller action accepts and which returns
45
- action(:change_user_password)
46
- .permit(:password!, :id!) # Bang (!) indicates that attribute is required
47
-
48
- def change_user_password
49
- user = User.find(params[:id])
50
- user.update!(password: params[:password])
51
-
52
- # returned value needs to have all methods defined in model `graphql do` part
53
- user # or SomeDecorator.new(user)
54
- end
55
-
56
- action(:search).permit(search_fields!: SearchFieldsInput) # you can specify your own input fields
57
- def search
58
- end
59
- end
60
- ```
61
-
62
- Congrats, you are done!
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'graphql_rails/types/argument_type'
4
- require 'graphql_rails/concerns/service'
5
-
6
- module GraphqlRails
7
- module Model
8
- # stores information about model specific config, like attributes and types
9
- class BuildGraphqlInputType
10
- include ::GraphqlRails::Service
11
-
12
- def initialize(name:, description: nil, attributes:)
13
- @name = name
14
- @attributes = attributes
15
- @description = description
16
- end
17
-
18
- def call
19
- type_name = name
20
- type_description = description
21
- type_attributes = attributes
22
-
23
- Class.new(GraphQL::Schema::InputObject) do
24
- argument_class(GraphqlRails::Types::ArgumentType)
25
- graphql_name(type_name)
26
- description(type_description)
27
-
28
- type_attributes.each_value do |type_attribute|
29
- argument(*type_attribute.input_argument_args, **type_attribute.input_argument_options)
30
- end
31
-
32
- def self.inspect
33
- "#{GraphQL::Schema::InputObject}(#{graphql_name})"
34
- end
35
- end
36
- end
37
-
38
- private
39
-
40
- attr_reader :model_configuration, :attributes, :name, :description
41
- end
42
- end
43
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'route'
4
-
5
- module GraphqlRails
6
- class Router
7
- # stores subscription type graphql action info
8
- class SubscriptionRoute < Route
9
- def query?
10
- false
11
- end
12
-
13
- def mutation?
14
- false
15
- end
16
-
17
- def subscription?
18
- true
19
- end
20
- end
21
- end
22
- end