ibrain-core 0.5.12 → 0.5.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/ibrain/core/graphql_controller.rb +40 -12
- data/app/graphql/ibrain/extentions/session_required.rb +9 -1
- data/app/graphql/ibrain/types/base_api_connection.rb +1 -1
- data/app/graphql/ibrain/types/base_connection.rb +1 -1
- data/lib/ibrain/core/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dcf708b989ce13166536ff15242a512355288a92efa79f547f73916f0815e63b
|
4
|
+
data.tar.gz: 8d440692e7c930935a416d8d9df2b8648b01e6f915f07cf1abf9d51d91083fb2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2b6ce0ddb2621a374cd3904273eb4229a0e31ca6f1cfcda2b06b07053fc289ed50404f6f44abdfee641be163fc341e5d2680a7726510eb7f853fd931c6f0d18
|
7
|
+
data.tar.gz: a541dd57fba71cbdb986655c8f471d29f920231725fb9276411ee8a178ebcf177726040650f723e6e063231b86587d14da207259bb767e90afa12b3443f98b1d
|
@@ -14,18 +14,46 @@ module Ibrain
|
|
14
14
|
def execute
|
15
15
|
query, variables, operation_name = normalize_entity
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
17
|
+
is_mutation = query =~ /mutation #{operation_name}/
|
18
|
+
cache_key = "graphql-#{try_ibrain_current_user&.id}/#{request.headers.hash}-#{params.to_unsafe_h.hash}"
|
19
|
+
context = {
|
20
|
+
session: session,
|
21
|
+
current_user: try_ibrain_current_user,
|
22
|
+
controller: self,
|
23
|
+
request: request
|
24
|
+
}
|
25
|
+
|
26
|
+
exec_function = proc do |options|
|
27
|
+
schema.execute(
|
28
|
+
options[:query],
|
29
|
+
variables: options[:variables],
|
30
|
+
context: options[:context],
|
31
|
+
operation_name: options[:operation_name],
|
32
|
+
max_depth: options[:max_depth]
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
if is_mutation
|
37
|
+
result = exec_function.call({
|
38
|
+
query: query,
|
39
|
+
variables: variables,
|
40
|
+
context: context,
|
41
|
+
operation_name: operation_name,
|
42
|
+
max_depth: max_depth(operation_name)
|
43
|
+
})
|
44
|
+
else
|
45
|
+
result = Rails.cache.fetch(cache_key, expires_in: 10.minutes) do
|
46
|
+
result = exec_function.call({
|
47
|
+
query: query,
|
48
|
+
variables: variables,
|
49
|
+
context: context,
|
50
|
+
operation_name: operation_name,
|
51
|
+
max_depth: max_depth(operation_name)
|
52
|
+
})
|
53
|
+
|
54
|
+
result.to_h
|
55
|
+
end
|
56
|
+
end
|
29
57
|
|
30
58
|
render_json_ok(result['data'], nil, result['errors'])
|
31
59
|
end
|
@@ -4,7 +4,10 @@ module Ibrain
|
|
4
4
|
module Extentions
|
5
5
|
class SessionRequired < GraphQL::Schema::FieldExtension
|
6
6
|
def resolve(object:, arguments:, **rest)
|
7
|
-
|
7
|
+
if is_invalid_session(object)
|
8
|
+
remove_device_token(object)
|
9
|
+
raise ActionController::InvalidAuthenticityToken, I18n.t('ibrain.errors.session.invalid_session')
|
10
|
+
end
|
8
11
|
|
9
12
|
# yield the current time as `memo`
|
10
13
|
yield(object, arguments, rest)
|
@@ -15,6 +18,11 @@ module Ibrain
|
|
15
18
|
def is_invalid_session(object)
|
16
19
|
object.try(:context).try(:fetch, :current_user, nil).blank? && options.try(:fetch, :session_required, false)
|
17
20
|
end
|
21
|
+
|
22
|
+
def remove_device_token(object)
|
23
|
+
request = object.try(:context).try(:fetch, :request, nil)
|
24
|
+
Ibrain.user_class.try(:remove_device_token, request) if request
|
25
|
+
end
|
18
26
|
end
|
19
27
|
end
|
20
28
|
end
|
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.5.
|
4
|
+
version: 0.5.15
|
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: 2023-
|
11
|
+
date: 2023-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord-session_store
|