ibrain-core 0.3.7.rc.pre.1 → 0.3.9
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/core/graphql_controller.rb +6 -1
- data/app/graphql/ibrain/base_schema.rb +3 -0
- data/app/graphql/ibrain/log_query_depth.rb +15 -0
- data/lib/generators/ibrain/graphql/mutation_generator.rb +2 -2
- data/lib/generators/ibrain/graphql/object_generator.rb +1 -1
- data/lib/generators/ibrain/graphql/resolvers_generator.rb +2 -2
- data/lib/generators/ibrain/graphql/templates/aggregate.erb +1 -1
- data/lib/generators/ibrain/graphql/templates/repository.erb +1 -1
- data/lib/generators/ibrain/graphql/type_generator.rb +1 -1
- data/lib/generators/ibrain/install/install_generator.rb +1 -0
- data/lib/generators/ibrain/install/templates/config/initializers/ibrain.rb.tt +4 -1
- data/lib/ibrain/app_configuration.rb +2 -0
- data/lib/ibrain/core/version.rb +2 -2
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54aa7f0b5250da9ca3b9855824c529007a2c01cbc12eaf63347298261c1422e7
|
4
|
+
data.tar.gz: 0c1f05cba8a7817f84b8c4cb85953ff5feea2f2a5753cda6a486498426133bb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ced3c27494f81a998bb7c6960141c58ce8902b44199668e63986771db01a5f033b4d59cf7a5518fc9f3442111582a8b7791e6f2e6700a0204b175132effb23a
|
7
|
+
data.tar.gz: d4f72b228c824b4fb68afa420a2caba8180e362ad35dcb154d81faf61fb420569407d7a4abc8f3637ae90b9ba10de3606e4687d6ee809d5281c9de34d45d0f8f
|
@@ -23,7 +23,8 @@ module Ibrain
|
|
23
23
|
controller: self,
|
24
24
|
request: request
|
25
25
|
},
|
26
|
-
operation_name: operation_name
|
26
|
+
operation_name: operation_name,
|
27
|
+
max_depth: max_depth(operation_name)
|
27
28
|
)
|
28
29
|
|
29
30
|
render_json_ok(result['data'], nil, result['errors'])
|
@@ -93,6 +94,10 @@ module Ibrain
|
|
93
94
|
|
94
95
|
request.env['devise.mapping'] = Ibrain.user_class
|
95
96
|
end
|
97
|
+
|
98
|
+
def max_depth(operation_name)
|
99
|
+
operation_name == 'IntrospectionQuery' ? 100 : Ibrain::Config.graphql_max_depth
|
100
|
+
end
|
96
101
|
end
|
97
102
|
end
|
98
103
|
end
|
@@ -4,6 +4,9 @@ module Ibrain
|
|
4
4
|
class BaseSchema < ::GraphQL::Schema
|
5
5
|
use GraphQL::Batch
|
6
6
|
|
7
|
+
max_depth Ibrain::Config.graphql_max_depth
|
8
|
+
query_analyzer(Ibrain::LogQueryDepth)
|
9
|
+
|
7
10
|
# use GraphQL::Guard.new(
|
8
11
|
# policy_object: ::Ibrain::Config.graphql_policy.safe_constantize,
|
9
12
|
# not_authorized: ->(type, field) { raise IbrainErrors::PermissionError.new("You not have permission to access #{type}.#{field}") }
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Ibrain::LogQueryDepth < GraphQL::Analysis::AST::QueryDepth
|
4
|
+
def result
|
5
|
+
query_depth = super
|
6
|
+
current_user = query.context[:current_user]
|
7
|
+
message = <<-RUBY
|
8
|
+
[GraphQL Query Depth]: #{query_depth}
|
9
|
+
[UserName]: #{current_user.try(:name)}
|
10
|
+
[UserID]: #{current_user.try(:id)}
|
11
|
+
RUBY
|
12
|
+
|
13
|
+
Rails.logger.info(message)
|
14
|
+
end
|
15
|
+
end
|
@@ -54,7 +54,7 @@ module Ibrain
|
|
54
54
|
def assign_names!(name)
|
55
55
|
underscore_name = name&.camelize&.underscore
|
56
56
|
prefix = options[:prefix].try(:underscore)
|
57
|
-
@model_name = options[:model].blank? ? 'Post' : options[:model].try(:
|
57
|
+
@model_name = options[:model].blank? ? 'Post' : options[:model].try(:camelize, :upper)
|
58
58
|
|
59
59
|
if prefix.blank?
|
60
60
|
@mutation_name = name.camelize(:upper)
|
@@ -64,7 +64,7 @@ module Ibrain
|
|
64
64
|
return
|
65
65
|
end
|
66
66
|
|
67
|
-
@mutation_name = "#{prefix.try(:
|
67
|
+
@mutation_name = "#{prefix.try(:camelize, :upper)}::#{name.camelize(:upper)}"
|
68
68
|
@file_name = "#{prefix}/#{underscore_name}"
|
69
69
|
@field_name = "#{prefix}_#{underscore_name}"
|
70
70
|
end
|
@@ -56,7 +56,7 @@ module Ibrain
|
|
56
56
|
underscore_name = name&.camelize&.underscore
|
57
57
|
prefix = options[:prefix].try(:underscore)
|
58
58
|
|
59
|
-
@model_name = options[:model].blank? ? 'Post' : options[:model].try(:
|
59
|
+
@model_name = options[:model].blank? ? 'Post' : options[:model].try(:camelize, :upper)
|
60
60
|
|
61
61
|
if prefix.blank?
|
62
62
|
@resolver_name = name.camelize(:upper)
|
@@ -66,7 +66,7 @@ module Ibrain
|
|
66
66
|
return
|
67
67
|
end
|
68
68
|
|
69
|
-
@resolver_name = "#{prefix.try(:
|
69
|
+
@resolver_name = "#{prefix.try(:camelize, :upper)}::#{name.camelize(:upper)}"
|
70
70
|
@file_name = "#{prefix}/#{underscore_name}"
|
71
71
|
@field_name = "#{prefix}_#{underscore_name}"
|
72
72
|
end
|
@@ -6,7 +6,7 @@ module Resolvers
|
|
6
6
|
description 'Define aggregate to count total records for <%= resolver_name %>'
|
7
7
|
# define resolve method
|
8
8
|
def resolve(args)
|
9
|
-
<%= model_name.
|
9
|
+
<%= model_name.try(:camelize, :upper) %>Repository.aggregate(args)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -24,7 +24,7 @@ module Ibrain
|
|
24
24
|
# @param mode [Symbol]
|
25
25
|
# @param null [Boolean]
|
26
26
|
# @return [(String, Boolean)] The type expression, followed by `null:` value
|
27
|
-
def self.normalize_type_expression(type_expression, mode:, null:
|
27
|
+
def self.normalize_type_expression(type_expression, mode:, null: false)
|
28
28
|
if type_expression.start_with?("!")
|
29
29
|
normalize_type_expression(type_expression[1..-1], mode: mode, null: false)
|
30
30
|
elsif type_expression.end_with?("!")
|
@@ -77,6 +77,7 @@ module Ibrain
|
|
77
77
|
append_gem('graphql-guard', '2.0.0')
|
78
78
|
append_gem('graphql-rails-generators', '1.1.2', 'development')
|
79
79
|
append_gem('graphiql-rails', '1.8.0', 'development')
|
80
|
+
append_gem('apollo_upload_server', '2.1')
|
80
81
|
end
|
81
82
|
|
82
83
|
append_gem('annotate', '3.1.1', 'development') if options[:with_annotation]
|
@@ -46,7 +46,10 @@ Ibrain.config do |config|
|
|
46
46
|
# config.parent_controller = 'ActionController::API'
|
47
47
|
|
48
48
|
# For multiple database
|
49
|
-
preference
|
49
|
+
# config.preference = 'primary'
|
50
|
+
|
51
|
+
# For max depth graphql
|
52
|
+
config.graphql_max_depth = 3
|
50
53
|
end
|
51
54
|
|
52
55
|
<% if defined?(Ibrain::Api::Engine) -%>
|
data/lib/ibrain/core/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ibrain-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tai Nguyen Van
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord-session_store
|
@@ -187,6 +187,7 @@ files:
|
|
187
187
|
- app/graphql/ibrain/interfaces/record_interface.rb
|
188
188
|
- app/graphql/ibrain/lazy/base.rb
|
189
189
|
- app/graphql/ibrain/loaders/association_loader.rb
|
190
|
+
- app/graphql/ibrain/log_query_depth.rb
|
190
191
|
- app/graphql/ibrain/mutations/base_mutation.rb
|
191
192
|
- app/graphql/ibrain/policies/base_policy.rb
|
192
193
|
- app/graphql/ibrain/policies/graphql_policy.rb
|
@@ -303,9 +304,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
303
304
|
version: '0'
|
304
305
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
305
306
|
requirements:
|
306
|
-
- - "
|
307
|
+
- - ">="
|
307
308
|
- !ruby/object:Gem::Version
|
308
|
-
version:
|
309
|
+
version: '0'
|
309
310
|
requirements: []
|
310
311
|
rubygems_version: 3.3.7
|
311
312
|
signing_key:
|