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.
- checksums.yaml +4 -4
- data/app/controllers/ibrain/base_controller.rb +14 -12
- data/app/controllers/ibrain/core/graphql_controller.rb +83 -79
- data/app/graphql/ibrain/base_schema.rb +52 -50
- data/app/graphql/ibrain/extentions/default_value.rb +11 -7
- data/app/graphql/ibrain/extentions/roles.rb +20 -15
- data/app/graphql/ibrain/extentions/session_required.rb +14 -10
- data/app/graphql/ibrain/lazy/base.rb +6 -2
- data/app/graphql/ibrain/loaders/association_loader.rb +55 -51
- data/app/graphql/ibrain/mutations/base_mutation.rb +56 -52
- data/app/graphql/ibrain/policies/base_policy.rb +47 -43
- data/app/graphql/ibrain/policies/graphql_policy.rb +6 -2
- data/app/graphql/ibrain/resolvers/base_aggregate.rb +10 -6
- data/app/graphql/ibrain/resolvers/base_resolver.rb +12 -8
- data/app/graphql/ibrain/types/aggregate_type.rb +8 -4
- data/app/graphql/ibrain/types/attribute_type.rb +5 -2
- data/app/graphql/ibrain/types/base_api_connection.rb +10 -6
- data/app/graphql/ibrain/types/base_api_edge.rb +8 -4
- data/app/graphql/ibrain/types/base_api_field.rb +11 -7
- data/app/graphql/ibrain/types/base_api_object.rb +10 -6
- data/app/graphql/ibrain/types/base_argument.rb +7 -3
- data/app/graphql/ibrain/types/base_connection.rb +11 -7
- data/app/graphql/ibrain/types/base_edge.rb +7 -3
- data/app/graphql/ibrain/types/base_enum.rb +5 -1
- data/app/graphql/ibrain/types/base_field.rb +10 -6
- data/app/graphql/ibrain/types/base_input_object.rb +10 -6
- data/app/graphql/ibrain/types/base_interface.rb +9 -5
- data/app/graphql/ibrain/types/base_object.rb +16 -12
- data/app/graphql/ibrain/types/base_scalar.rb +5 -1
- data/app/graphql/ibrain/types/base_type.rb +10 -4
- data/app/graphql/ibrain/types/base_union.rb +7 -3
- data/app/graphql/ibrain/types/filter_type.rb +5 -1
- data/app/graphql/ibrain/types/node_type.rb +8 -4
- data/app/graphql/ibrain/util/field_combiner.rb +9 -5
- data/app/graphql/ibrain/util/query_combiner.rb +8 -4
- data/app/models/concerns/ibrain/soft_deletable.rb +8 -6
- data/app/models/concerns/ibrain/user_api_authentication.rb +16 -14
- data/app/models/concerns/ibrain/user_methods.rb +13 -11
- data/app/models/ibrain/ability.rb +32 -31
- data/app/models/ibrain/aggregate.rb +7 -5
- data/app/models/ibrain/application_record.rb +4 -2
- data/app/models/ibrain/legacy_user.rb +13 -7
- data/app/models/ibrain/role.rb +8 -6
- data/app/models/ibrain/role_user.rb +10 -8
- data/app/repositories/ibrain/base_repository.rb +11 -9
- data/lib/generators/ibrain/core/model_generator.rb +21 -17
- data/lib/generators/ibrain/graphql/core.rb +59 -55
- data/lib/generators/ibrain/graphql/mutation_generator.rb +66 -58
- data/lib/generators/ibrain/graphql/object_generator.rb +70 -58
- data/lib/generators/ibrain/graphql/resolver_generator.rb +25 -17
- data/lib/generators/ibrain/graphql/resolvers_generator.rb +67 -59
- data/lib/generators/ibrain/graphql/templates/aggregate.erb +7 -5
- data/lib/generators/ibrain/graphql/templates/input.erb +9 -5
- data/lib/generators/ibrain/graphql/templates/mutation.erb +26 -24
- data/lib/generators/ibrain/graphql/templates/object.erb +10 -6
- data/lib/generators/ibrain/graphql/templates/resolver.erb +11 -9
- data/lib/generators/ibrain/graphql/templates/resolvers.erb +10 -8
- data/lib/generators/ibrain/graphql/type_generator.rb +88 -84
- data/lib/generators/ibrain/install/install_generator.rb +140 -137
- data/lib/generators/ibrain/install/templates/graphql/types/mutation_type.rb.tt +15 -13
- data/lib/generators/ibrain/install/templates/graphql/types/query_type.rb.tt +13 -11
- data/lib/generators/ibrain/install/templates/rubocop.yml.tt +30 -83
- data/lib/ibrain/app_configuration.rb +36 -34
- data/lib/ibrain/core/class_constantizer.rb +33 -30
- data/lib/ibrain/core/controller_helpers/auth.rb +59 -53
- data/lib/ibrain/core/controller_helpers/current_host.rb +11 -5
- data/lib/ibrain/core/controller_helpers/response.rb +49 -43
- data/lib/ibrain/core/controller_helpers/strong_parameters.rb +15 -9
- data/lib/ibrain/core/engine.rb +9 -5
- data/lib/ibrain/core/environment.rb +9 -5
- data/lib/ibrain/core/environment_extension.rb +17 -13
- data/lib/ibrain/core/role_configuration.rb +54 -52
- data/lib/ibrain/core/validators/email.rb +17 -15
- data/lib/ibrain/core/version.rb +2 -2
- data/lib/ibrain/core/versioned_value.rb +65 -61
- data/lib/ibrain/encryptor.rb +20 -18
- data/lib/ibrain/logger.rb +15 -13
- data/lib/ibrain/permission_sets/base.rb +26 -22
- data/lib/ibrain/permission_sets/super_user.rb +7 -3
- data/lib/ibrain/permitted_attributes.rb +20 -18
- data/lib/ibrain/preferences/configuration.rb +137 -135
- data/lib/ibrain/preferences/preferable.rb +162 -158
- data/lib/ibrain/preferences/preferable_class_methods.rb +114 -112
- data/lib/ibrain/user_class_handle.rb +24 -22
- data/lib/ibrain_core.rb +1 -7
- metadata +1 -1
|
@@ -1,69 +1,73 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
+
argument :attribute, Types::AttributeType, required: false
|
|
12
|
+
argument :attributes, [Types::AttributeType], required: false
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
22
|
+
protected
|
|
21
23
|
|
|
22
|
-
|
|
24
|
+
attr_reader :params, :resource
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
def upload_permitted
|
|
27
|
+
%i[content_type headers original_filename tempfile]
|
|
28
|
+
end
|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
def cryptor
|
|
31
|
+
::Ibrain::Encryptor.new
|
|
32
|
+
end
|
|
31
33
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
def current_user
|
|
35
|
+
context[:current_user]
|
|
36
|
+
end
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
def controller
|
|
39
|
+
context[:controller]
|
|
40
|
+
end
|
|
39
41
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
def session
|
|
43
|
+
context[:session]
|
|
44
|
+
end
|
|
43
45
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
def request
|
|
47
|
+
context[:request]
|
|
48
|
+
end
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
def graphql_return
|
|
51
|
+
{
|
|
52
|
+
returning: resource.reload
|
|
53
|
+
}
|
|
54
|
+
end
|
|
53
55
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
def success_response
|
|
57
|
+
{
|
|
58
|
+
success: true
|
|
59
|
+
}
|
|
60
|
+
end
|
|
59
61
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
def id_from_params
|
|
63
|
+
params[:id]
|
|
64
|
+
end
|
|
63
65
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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,9 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
module Ibrain
|
|
4
|
+
module Resolvers
|
|
5
|
+
class BaseAggregate < BaseResolver
|
|
6
|
+
type Ibrain::Types::BaseObject.connection_type, null: false
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
4
|
-
|
|
3
|
+
module Ibrain
|
|
4
|
+
module Resolvers
|
|
5
|
+
class BaseResolver < GraphQL::Schema::Resolver
|
|
6
|
+
argument_class ::Ibrain::Types::BaseArgument
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
def current_user
|
|
9
|
+
context.fetch(:current_user)
|
|
10
|
+
end
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
4
|
-
|
|
3
|
+
module Ibrain
|
|
4
|
+
module Types
|
|
5
|
+
class AggregateType < BaseObject
|
|
6
|
+
graphql_name 'aggregate'
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
end
|
|
8
|
+
field :count, Int, null: false
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
9
|
+
field :aggregate, Ibrain::Types::AggregateType, null: false, camelize: false
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
4
|
-
|
|
3
|
+
module Ibrain
|
|
4
|
+
module Types
|
|
5
|
+
class BaseApiField < GraphQL::Schema::Field
|
|
6
|
+
argument_class ::Ibrain::Types::BaseArgument
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
def initialize(*args, session_required: true, roles: nil, **kwargs, &block)
|
|
9
|
+
super(*args, camelize: false, **kwargs, &block)
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
4
|
-
|
|
3
|
+
module Ibrain
|
|
4
|
+
module Types
|
|
5
|
+
class BaseApiObject < GraphQL::Schema::Object
|
|
6
|
+
include GraphQL::Relay::Node
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
edge_type_class(Ibrain::Types::BaseApiEdge)
|
|
9
|
+
connection_type_class(Ibrain::Types::BaseApiConnection)
|
|
8
10
|
|
|
9
|
-
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
9
|
+
field :aggregate, Ibrain::Types::AggregateType, null: false, camelize: false
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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,12 +1,16 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
module Ibrain
|
|
4
|
+
module Types
|
|
5
|
+
class BaseField < GraphQL::Schema::Field
|
|
6
|
+
argument_class ::Ibrain::Types::BaseArgument
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
def initialize(*args, default_value: nil, roles: nil, **kwargs, &block)
|
|
9
|
+
super(*args, camelize: false, **kwargs, &block)
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
4
|
-
|
|
3
|
+
module Ibrain
|
|
4
|
+
module Types
|
|
5
|
+
class BaseInputObject < GraphQL::Schema::InputObject
|
|
6
|
+
argument_class Ibrain::Types::BaseArgument
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
4
|
-
|
|
3
|
+
module Ibrain
|
|
4
|
+
module Types
|
|
5
|
+
module BaseInterface
|
|
6
|
+
include GraphQL::Schema::Interface
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
edge_type_class(Ibrain::Types::BaseEdge)
|
|
9
|
+
connection_type_class(Ibrain::Types::BaseConnection)
|
|
8
10
|
|
|
9
|
-
|
|
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
|
-
|
|
4
|
-
|
|
3
|
+
module Ibrain
|
|
4
|
+
module Types
|
|
5
|
+
class BaseObject < GraphQL::Schema::Object
|
|
6
|
+
include GraphQL::Relay::Node
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
edge_type_class(Ibrain::Types::BaseEdge)
|
|
9
|
+
connection_type_class(Ibrain::Types::BaseConnection)
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
field_class ::Ibrain::Types::BaseField
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
field :name, String, null: true
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
protected
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
def loader
|
|
18
|
+
Ibrain::Loaders::AssociationLoader
|
|
19
|
+
end
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
def current_user
|
|
22
|
+
context.try(:fetch, :current_user)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
21
25
|
end
|
|
22
26
|
end
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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,7 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
module Ibrain
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|