ibrain-core 0.4.6 → 0.4.7

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 (86) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/ibrain/base_controller.rb +14 -12
  3. data/app/controllers/ibrain/core/graphql_controller.rb +83 -79
  4. data/app/graphql/ibrain/base_schema.rb +52 -50
  5. data/app/graphql/ibrain/extentions/default_value.rb +11 -7
  6. data/app/graphql/ibrain/extentions/roles.rb +20 -15
  7. data/app/graphql/ibrain/extentions/session_required.rb +14 -10
  8. data/app/graphql/ibrain/lazy/base.rb +6 -2
  9. data/app/graphql/ibrain/loaders/association_loader.rb +55 -51
  10. data/app/graphql/ibrain/mutations/base_mutation.rb +56 -52
  11. data/app/graphql/ibrain/policies/base_policy.rb +47 -43
  12. data/app/graphql/ibrain/policies/graphql_policy.rb +6 -2
  13. data/app/graphql/ibrain/resolvers/base_aggregate.rb +10 -6
  14. data/app/graphql/ibrain/resolvers/base_resolver.rb +12 -8
  15. data/app/graphql/ibrain/types/aggregate_type.rb +8 -4
  16. data/app/graphql/ibrain/types/attribute_type.rb +5 -2
  17. data/app/graphql/ibrain/types/base_api_connection.rb +10 -6
  18. data/app/graphql/ibrain/types/base_api_edge.rb +8 -4
  19. data/app/graphql/ibrain/types/base_api_field.rb +11 -7
  20. data/app/graphql/ibrain/types/base_api_object.rb +10 -6
  21. data/app/graphql/ibrain/types/base_argument.rb +7 -3
  22. data/app/graphql/ibrain/types/base_connection.rb +11 -7
  23. data/app/graphql/ibrain/types/base_edge.rb +7 -3
  24. data/app/graphql/ibrain/types/base_enum.rb +5 -1
  25. data/app/graphql/ibrain/types/base_field.rb +10 -6
  26. data/app/graphql/ibrain/types/base_input_object.rb +10 -6
  27. data/app/graphql/ibrain/types/base_interface.rb +9 -5
  28. data/app/graphql/ibrain/types/base_object.rb +16 -12
  29. data/app/graphql/ibrain/types/base_scalar.rb +5 -1
  30. data/app/graphql/ibrain/types/base_type.rb +10 -4
  31. data/app/graphql/ibrain/types/base_union.rb +7 -3
  32. data/app/graphql/ibrain/types/filter_type.rb +5 -1
  33. data/app/graphql/ibrain/types/node_type.rb +8 -4
  34. data/app/graphql/ibrain/util/field_combiner.rb +9 -5
  35. data/app/graphql/ibrain/util/query_combiner.rb +8 -4
  36. data/app/models/concerns/ibrain/soft_deletable.rb +8 -6
  37. data/app/models/concerns/ibrain/user_api_authentication.rb +16 -14
  38. data/app/models/concerns/ibrain/user_methods.rb +13 -11
  39. data/app/models/ibrain/ability.rb +32 -31
  40. data/app/models/ibrain/aggregate.rb +7 -5
  41. data/app/models/ibrain/application_record.rb +4 -2
  42. data/app/models/ibrain/legacy_user.rb +13 -7
  43. data/app/models/ibrain/role.rb +8 -6
  44. data/app/models/ibrain/role_user.rb +10 -8
  45. data/app/repositories/ibrain/base_repository.rb +11 -9
  46. data/lib/generators/ibrain/core/model_generator.rb +21 -17
  47. data/lib/generators/ibrain/graphql/core.rb +59 -55
  48. data/lib/generators/ibrain/graphql/mutation_generator.rb +66 -58
  49. data/lib/generators/ibrain/graphql/object_generator.rb +70 -58
  50. data/lib/generators/ibrain/graphql/resolver_generator.rb +25 -17
  51. data/lib/generators/ibrain/graphql/resolvers_generator.rb +67 -59
  52. data/lib/generators/ibrain/graphql/templates/aggregate.erb +7 -5
  53. data/lib/generators/ibrain/graphql/templates/input.erb +9 -5
  54. data/lib/generators/ibrain/graphql/templates/mutation.erb +26 -24
  55. data/lib/generators/ibrain/graphql/templates/object.erb +10 -6
  56. data/lib/generators/ibrain/graphql/templates/resolver.erb +11 -9
  57. data/lib/generators/ibrain/graphql/templates/resolvers.erb +10 -8
  58. data/lib/generators/ibrain/graphql/type_generator.rb +88 -84
  59. data/lib/generators/ibrain/install/install_generator.rb +140 -137
  60. data/lib/generators/ibrain/install/templates/graphql/types/mutation_type.rb.tt +15 -13
  61. data/lib/generators/ibrain/install/templates/graphql/types/query_type.rb.tt +13 -11
  62. data/lib/generators/ibrain/install/templates/rubocop.yml.tt +30 -83
  63. data/lib/ibrain/app_configuration.rb +36 -34
  64. data/lib/ibrain/core/class_constantizer.rb +33 -30
  65. data/lib/ibrain/core/controller_helpers/auth.rb +59 -53
  66. data/lib/ibrain/core/controller_helpers/current_host.rb +11 -5
  67. data/lib/ibrain/core/controller_helpers/response.rb +49 -43
  68. data/lib/ibrain/core/controller_helpers/strong_parameters.rb +15 -9
  69. data/lib/ibrain/core/engine.rb +9 -5
  70. data/lib/ibrain/core/environment.rb +9 -5
  71. data/lib/ibrain/core/environment_extension.rb +17 -13
  72. data/lib/ibrain/core/role_configuration.rb +54 -52
  73. data/lib/ibrain/core/validators/email.rb +17 -15
  74. data/lib/ibrain/core/version.rb +2 -2
  75. data/lib/ibrain/core/versioned_value.rb +65 -61
  76. data/lib/ibrain/encryptor.rb +20 -18
  77. data/lib/ibrain/logger.rb +15 -13
  78. data/lib/ibrain/permission_sets/base.rb +26 -22
  79. data/lib/ibrain/permission_sets/super_user.rb +7 -3
  80. data/lib/ibrain/permitted_attributes.rb +20 -18
  81. data/lib/ibrain/preferences/configuration.rb +137 -135
  82. data/lib/ibrain/preferences/preferable.rb +162 -158
  83. data/lib/ibrain/preferences/preferable_class_methods.rb +114 -112
  84. data/lib/ibrain/user_class_handle.rb +24 -22
  85. data/lib/ibrain_core.rb +1 -7
  86. metadata +1 -1
@@ -1,69 +1,73 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Ibrain::Mutations::BaseMutation < GraphQL::Schema::RelayClassicMutation
4
- argument_class Types::BaseArgument
5
- field_class Types::BaseField
6
- input_object_class Types::BaseInputObject
7
- object_class Types::BaseObject
3
+ module Ibrain
4
+ module Mutations
5
+ class BaseMutation < GraphQL::Schema::RelayClassicMutation
6
+ argument_class Types::BaseArgument
7
+ field_class Types::BaseField
8
+ input_object_class Types::BaseInputObject
9
+ object_class Types::BaseObject
8
10
 
9
- argument :attribute, Types::AttributeType, required: false
10
- argument :attributes, [Types::AttributeType], required: false
11
+ argument :attribute, Types::AttributeType, required: false
12
+ argument :attributes, [Types::AttributeType], required: false
11
13
 
12
- def ready?(args)
13
- @params = ActionController::Parameters.new(
14
- args.to_h.with_indifferent_access.transform_keys(&:underscore)
15
- )
16
- @resource = load_resource
17
- true
18
- end
14
+ def ready?(args)
15
+ @params = ActionController::Parameters.new(
16
+ args.to_h.with_indifferent_access.transform_keys(&:underscore)
17
+ )
18
+ @resource = load_resource
19
+ true
20
+ end
19
21
 
20
- protected
22
+ protected
21
23
 
22
- attr_reader :params, :resource
24
+ attr_reader :params, :resource
23
25
 
24
- def upload_permitted
25
- %i[content_type headers original_filename tempfile]
26
- end
26
+ def upload_permitted
27
+ %i[content_type headers original_filename tempfile]
28
+ end
27
29
 
28
- def cryptor
29
- ::Ibrain::Encryptor.new
30
- end
30
+ def cryptor
31
+ ::Ibrain::Encryptor.new
32
+ end
31
33
 
32
- def current_user
33
- context[:current_user]
34
- end
34
+ def current_user
35
+ context[:current_user]
36
+ end
35
37
 
36
- def controller
37
- context[:controller]
38
- end
38
+ def controller
39
+ context[:controller]
40
+ end
39
41
 
40
- def session
41
- context[:session]
42
- end
42
+ def session
43
+ context[:session]
44
+ end
43
45
 
44
- def request
45
- context[:request]
46
- end
46
+ def request
47
+ context[:request]
48
+ end
47
49
 
48
- def graphql_return
49
- {
50
- returning: resource.reload
51
- }
52
- end
50
+ def graphql_return
51
+ {
52
+ returning: resource.reload
53
+ }
54
+ end
53
55
 
54
- def success_response
55
- {
56
- success: true
57
- }
58
- end
56
+ def success_response
57
+ {
58
+ success: true
59
+ }
60
+ end
59
61
 
60
- def id_from_params
61
- params[:id]
62
- end
62
+ def id_from_params
63
+ params[:id]
64
+ end
63
65
 
64
- def attribute_params
65
- params[:attributes].to_params
66
- rescue StandardError
67
- ActionController::Parameters.new({})
66
+ def attribute_params
67
+ params[:attributes].to_params
68
+ rescue StandardError
69
+ ActionController::Parameters.new({})
70
+ end
71
+ end
68
72
  end
69
- end
73
+ end
@@ -1,47 +1,51 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Ibrain::Policies::BasePolicy
4
- class << self
5
- def query_rules
6
- {
7
- '*': {
8
- guard: ->(_obj, _args, _ctx) { false }
9
- }
10
- }
11
- end
12
-
13
- def mutation_rules
14
- {
15
- '*': {
16
- guard: ->(_obj, _args, _ctx) { false }
17
- }
18
- }
19
- end
20
-
21
- def rules
22
- {
23
- 'Types::QueryType' => query_rules,
24
- 'Types::MutationType' => mutation_rules
25
- }.freeze
26
- end
27
-
28
- def roles
29
- Ibrain.user_class.roles.keys
30
- end
31
-
32
- def has_permission?(current_user, resource)
33
- return false if current_user.blank?
34
- return true if current_user.super_admin?
35
-
36
- current_user.try(:scope).to_s.split(',').include?(resource)
37
- end
38
-
39
- def guard(type, field)
40
- rules.dig(type.name, field, :guard)
41
- end
42
-
43
- def not_authorized_handler(type, field)
44
- rules.dig(type, field, :not_authorized) || rules.dig(type, :*, :not_authorized)
3
+ module Ibrain
4
+ module Policies
5
+ class BasePolicy
6
+ class << self
7
+ def query_rules
8
+ {
9
+ '*': {
10
+ guard: ->(_obj, _args, _ctx) { false }
11
+ }
12
+ }
13
+ end
14
+
15
+ def mutation_rules
16
+ {
17
+ '*': {
18
+ guard: ->(_obj, _args, _ctx) { false }
19
+ }
20
+ }
21
+ end
22
+
23
+ def rules
24
+ {
25
+ 'Types::QueryType' => query_rules,
26
+ 'Types::MutationType' => mutation_rules
27
+ }.freeze
28
+ end
29
+
30
+ def roles
31
+ Ibrain.user_class.roles.keys
32
+ end
33
+
34
+ def has_permission?(current_user, resource)
35
+ return false if current_user.blank?
36
+ return true if current_user.super_admin?
37
+
38
+ current_user.try(:scope).to_s.split(',').include?(resource)
39
+ end
40
+
41
+ def guard(type, field)
42
+ rules.dig(type.name, field, :guard)
43
+ end
44
+
45
+ def not_authorized_handler(type, field)
46
+ rules.dig(type, field, :not_authorized) || rules.dig(type, :*, :not_authorized)
47
+ end
48
+ end
45
49
  end
46
50
  end
47
- end
51
+ end
@@ -1,4 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Ibrain::Policies::GraphqlPolicy < BasePolicy
4
- end
3
+ module Ibrain
4
+ module Policies
5
+ class GraphqlPolicy < BasePolicy
6
+ end
7
+ end
8
+ end
@@ -1,9 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Ibrain::Resolvers::BaseAggregate < BaseResolver
4
- type Ibrain::Types::BaseObject.connection_type, null: false
3
+ module Ibrain
4
+ module Resolvers
5
+ class BaseAggregate < BaseResolver
6
+ type Ibrain::Types::BaseObject.connection_type, null: false
5
7
 
6
- argument :where, Ibrain::Types::FilterType, required: false, default_value: nil
7
- argument :limit, Int, required: false, default_value: 10
8
- argument :offset, Int, required: false, default_value: 0
9
- end
8
+ argument :where, Ibrain::Types::FilterType, required: false, default_value: nil
9
+ argument :limit, Int, required: false, default_value: 10
10
+ argument :offset, Int, required: false, default_value: 0
11
+ end
12
+ end
13
+ end
@@ -1,13 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Ibrain::Resolvers::BaseResolver < GraphQL::Schema::Resolver
4
- argument_class ::Ibrain::Types::BaseArgument
3
+ module Ibrain
4
+ module Resolvers
5
+ class BaseResolver < GraphQL::Schema::Resolver
6
+ argument_class ::Ibrain::Types::BaseArgument
5
7
 
6
- def current_user
7
- context.fetch(:current_user)
8
- end
8
+ def current_user
9
+ context.fetch(:current_user)
10
+ end
9
11
 
10
- def controller
11
- context[:controller]
12
+ def controller
13
+ context[:controller]
14
+ end
15
+ end
12
16
  end
13
- end
17
+ end
@@ -1,7 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Ibrain::Types::AggregateType < Ibrain::Types::BaseObject
4
- graphql_name 'aggregate'
3
+ module Ibrain
4
+ module Types
5
+ class AggregateType < BaseObject
6
+ graphql_name 'aggregate'
5
7
 
6
- field :count, Int, null: false
7
- end
8
+ field :count, Int, null: false
9
+ end
10
+ end
11
+ end
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
-
4
- class Ibrain::Types::AttributeType < Ibrain::Types::BaseScalar
3
+ module Ibrain
4
+ module Types
5
+ class AttributeType < BaseScalar
6
+ end
7
+ end
5
8
  end
@@ -1,12 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Ibrain::Types::BaseApiConnection < Ibrain::Types::BaseObject
4
- # add `nodes` and `pageInfo` fields, as well as `edge_type(...)` and `node_nullable(...)` overrides
5
- include GraphQL::Types::Relay::ConnectionBehaviors
3
+ module Ibrain
4
+ module Types
5
+ class BaseApiConnection < Types::BaseObject
6
+ # add `nodes` and `pageInfo` fields, as well as `edge_type(...)` and `node_nullable(...)` overrides
7
+ include GraphQL::Types::Relay::ConnectionBehaviors
6
8
 
7
- field :aggregate, Ibrain::Types::AggregateType, null: false, camelize: false
9
+ field :aggregate, Ibrain::Types::AggregateType, null: false, camelize: false
8
10
 
9
- def aggregate
10
- Ibrain::Aggregate.new(object.items.size)
11
+ def aggregate
12
+ Ibrain::Aggregate.new(object.items.size)
13
+ end
14
+ end
11
15
  end
12
16
  end
@@ -1,6 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Ibrain::Types::BaseApiEdge < Ibrain::Types::BaseObject
4
- # add `node` and `cursor` fields, as well as `node_type(...)` override
5
- include GraphQL::Types::Relay::EdgeBehaviors
6
- end
3
+ module Ibrain
4
+ module Types
5
+ class BaseApiEdge < Types::BaseObject
6
+ # add `node` and `cursor` fields, as well as `node_type(...)` override
7
+ include GraphQL::Types::Relay::EdgeBehaviors
8
+ end
9
+ end
10
+ end
@@ -1,12 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Ibrain::Types::BaseApiField < GraphQL::Schema::Field
4
- argument_class Ibrain::Types::BaseArgument
3
+ module Ibrain
4
+ module Types
5
+ class BaseApiField < GraphQL::Schema::Field
6
+ argument_class ::Ibrain::Types::BaseArgument
5
7
 
6
- def initialize(*args, session_required: true, roles: nil, **kwargs, &block)
7
- super(*args, camelize: false, **kwargs, &block)
8
+ def initialize(*args, session_required: true, roles: nil, **kwargs, &block)
9
+ super(*args, camelize: false, **kwargs, &block)
8
10
 
9
- extension(Ibrain::Extentions::SessionRequired, session_required: session_required) if session_required
10
- extension(Ibrain::Extentions::Roles, roles: roles) if roles
11
+ extension(Ibrain::Extentions::SessionRequired, session_required: session_required) if session_required
12
+ extension(Ibrain::Extentions::Roles, roles: roles) if roles
13
+ end
14
+ end
11
15
  end
12
- end
16
+ end
@@ -1,10 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Ibrain::Types::BaseApiObject < GraphQL::Schema::Object
4
- include GraphQL::Relay::Node
3
+ module Ibrain
4
+ module Types
5
+ class BaseApiObject < GraphQL::Schema::Object
6
+ include GraphQL::Relay::Node
5
7
 
6
- edge_type_class(Ibrain::Types::BaseApiEdge)
7
- connection_type_class(Ibrain::Types::BaseApiConnection)
8
+ edge_type_class(Ibrain::Types::BaseApiEdge)
9
+ connection_type_class(Ibrain::Types::BaseApiConnection)
8
10
 
9
- field_class Ibrain::Types::BaseApiField
10
- end
11
+ field_class Ibrain::Types::BaseApiField
12
+ end
13
+ end
14
+ end
@@ -1,7 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Ibrain::Types::BaseArgument < GraphQL::Schema::Argument
4
- def initialize(*args, **kwargs, &block)
5
- super(*args, camelize: false, **kwargs, &block)
3
+ module Ibrain
4
+ module Types
5
+ class BaseArgument < GraphQL::Schema::Argument
6
+ def initialize(*args, **kwargs, &block)
7
+ super(*args, camelize: false, **kwargs, &block)
8
+ end
9
+ end
6
10
  end
7
11
  end
@@ -1,12 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Ibrain::Types::BaseConnection < Types::BaseObject
4
- # add `nodes` and `pageInfo` fields, as well as `edge_type(...)` and `node_nullable(...)` overrides
5
- include GraphQL::Types::Relay::ConnectionBehaviors
3
+ module Ibrain
4
+ module Types
5
+ class BaseConnection < Types::BaseObject
6
+ # add `nodes` and `pageInfo` fields, as well as `edge_type(...)` and `node_nullable(...)` overrides
7
+ include GraphQL::Types::Relay::ConnectionBehaviors
6
8
 
7
- field :aggregate, Ibrain::Types::AggregateType, null: false, camelize: false
9
+ field :aggregate, Ibrain::Types::AggregateType, null: false, camelize: false
8
10
 
9
- def aggregate
10
- Ibrain::Aggregate.new(object.items.size)
11
+ def aggregate
12
+ Ibrain::Aggregate.new(object.items.size)
13
+ end
14
+ end
11
15
  end
12
- end
16
+ end
@@ -1,6 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Ibrain::Types::BaseEdge < Types::BaseObject
4
- # add `node` and `cursor` fields, as well as `node_type(...)` override
5
- include GraphQL::Types::Relay::EdgeBehaviors
3
+ module Ibrain
4
+ module Types
5
+ class BaseEdge < Types::BaseObject
6
+ # add `node` and `cursor` fields, as well as `node_type(...)` override
7
+ include GraphQL::Types::Relay::EdgeBehaviors
8
+ end
9
+ end
6
10
  end
@@ -1,4 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Ibrain::Types::BaseEnum < GraphQL::Schema::Enum
3
+ module Ibrain
4
+ module Types
5
+ class BaseEnum < GraphQL::Schema::Enum
6
+ end
7
+ end
4
8
  end
@@ -1,12 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Ibrain::Types::BaseField < GraphQL::Schema::Field
4
- argument_class Ibrain::Types::BaseArgument
3
+ module Ibrain
4
+ module Types
5
+ class BaseField < GraphQL::Schema::Field
6
+ argument_class ::Ibrain::Types::BaseArgument
5
7
 
6
- def initialize(*args, default_value: nil, roles: nil, **kwargs, &block)
7
- super(*args, camelize: false, **kwargs, &block)
8
+ def initialize(*args, default_value: nil, roles: nil, **kwargs, &block)
9
+ super(*args, camelize: false, **kwargs, &block)
8
10
 
9
- extension(Ibrain::Extentions::DefaultValue, default_value: default_value) unless default_value.nil?
10
- extension(Ibrain::Extentions::Roles, roles: roles) if roles
11
+ extension(::Ibrain::Extentions::DefaultValue, default_value: default_value) unless default_value.nil?
12
+ extension(Ibrain::Extentions::Roles, roles: roles) if roles
13
+ end
14
+ end
11
15
  end
12
16
  end
@@ -1,11 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Ibrain::Types::BaseInputObject < GraphQL::Schema::InputObject
4
- argument_class Ibrain::Types::BaseArgument
3
+ module Ibrain
4
+ module Types
5
+ class BaseInputObject < GraphQL::Schema::InputObject
6
+ argument_class Ibrain::Types::BaseArgument
5
7
 
6
- def to_params
7
- ActionController::Parameters.new(
8
- to_h.with_indifferent_access.transform_keys(&:underscore)
9
- )
8
+ def to_params
9
+ ActionController::Parameters.new(
10
+ to_h.with_indifferent_access.transform_keys(&:underscore)
11
+ )
12
+ end
13
+ end
10
14
  end
11
15
  end
@@ -1,10 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Ibrain::Types::BaseInterface
4
- include GraphQL::Schema::Interface
3
+ module Ibrain
4
+ module Types
5
+ module BaseInterface
6
+ include GraphQL::Schema::Interface
5
7
 
6
- edge_type_class(Ibrain::Types::BaseEdge)
7
- connection_type_class(Ibrain::Types::BaseConnection)
8
+ edge_type_class(Ibrain::Types::BaseEdge)
9
+ connection_type_class(Ibrain::Types::BaseConnection)
8
10
 
9
- field_class Ibrain::Types::BaseField
11
+ field_class Ibrain::Types::BaseField
12
+ end
13
+ end
10
14
  end
@@ -1,22 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Ibrain::Types::BaseObject < GraphQL::Schema::Object
4
- include GraphQL::Relay::Node
3
+ module Ibrain
4
+ module Types
5
+ class BaseObject < GraphQL::Schema::Object
6
+ include GraphQL::Relay::Node
5
7
 
6
- edge_type_class(Ibrain::Types::BaseEdge)
7
- connection_type_class(Ibrain::Types::BaseConnection)
8
+ edge_type_class(Ibrain::Types::BaseEdge)
9
+ connection_type_class(Ibrain::Types::BaseConnection)
8
10
 
9
- field_class Ibrain::Types::BaseField
11
+ field_class ::Ibrain::Types::BaseField
10
12
 
11
- field :name, String, null: true
13
+ field :name, String, null: true
12
14
 
13
- protected
15
+ protected
14
16
 
15
- def loader
16
- Ibrain::Loaders::AssociationLoader
17
- end
17
+ def loader
18
+ Ibrain::Loaders::AssociationLoader
19
+ end
18
20
 
19
- def current_user
20
- context.try(:fetch, :current_user)
21
+ def current_user
22
+ context.try(:fetch, :current_user)
23
+ end
24
+ end
21
25
  end
22
26
  end
@@ -1,4 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Ibrain::Types::BaseScalar < GraphQL::Schema::Scalar
3
+ module Ibrain
4
+ module Types
5
+ class BaseScalar < GraphQL::Schema::Scalar
6
+ end
7
+ end
4
8
  end
@@ -1,7 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Ibrain::Types::BaseType < Ibrain::Types::BaseObject
4
- def self.graphql_name
5
- self.class.table_name
3
+ module Ibrain
4
+ module Types
5
+ class BaseType < BaseObject
6
+ def self.graphql_name(name = "")
7
+ return name if name.present?
8
+
9
+ self.name.demodulize.gsub('Type', '').classify.constantize.table_name
10
+ end
11
+ end
6
12
  end
7
- end
13
+ end
@@ -1,6 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Ibrain::Types::BaseUnion < GraphQL::Schema::Union
4
- edge_type_class(Ibrain::Types::BaseEdge)
5
- connection_type_class(Ibrain::Types::BaseConnection)
3
+ module Ibrain
4
+ module Types
5
+ class BaseUnion < GraphQL::Schema::Union
6
+ edge_type_class(Ibrain::Types::BaseEdge)
7
+ connection_type_class(Ibrain::Types::BaseConnection)
8
+ end
9
+ end
6
10
  end
@@ -1,4 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Ibrain::Types::FilterType < GraphQL::Schema::Scalar
3
+ module Ibrain
4
+ module Types
5
+ class FilterType < GraphQL::Schema::Scalar
6
+ end
7
+ end
4
8
  end
@@ -1,7 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Ibrain::Types::NodeType
4
- include Ibrain::Types::BaseInterface
5
- # Add the `id` field
6
- include GraphQL::Types::Relay::NodeBehaviors
3
+ module Ibrain
4
+ module Types
5
+ module NodeType
6
+ include Ibrain::Types::BaseInterface
7
+ # Add the `id` field
8
+ include GraphQL::Types::Relay::NodeBehaviors
9
+ end
10
+ end
7
11
  end
@@ -1,9 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Ibrain::Util::FieldCombiner
4
- def self.combine(query_types)
5
- Array(query_types).inject({}) do |acc, query_type|
6
- acc.merge!(query_type.fields)
3
+ module Ibrain
4
+ module Util
5
+ class FieldCombiner
6
+ def self.combine(query_types)
7
+ Array(query_types).inject({}) do |acc, query_type|
8
+ acc.merge!(query_type.fields)
9
+ end
10
+ end
7
11
  end
8
12
  end
9
- end
13
+ end