graph_attack 2.1.0 → 2.2.0
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/CHANGELOG.md +6 -0
- data/README.md +2 -0
- data/lib/graph_attack/rate_limit.rb +8 -9
- data/lib/graph_attack/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: 8e7c2758ed10d1304e998ecdfb980897aec795513e69eaef79cfcc7b0d42b76f
|
4
|
+
data.tar.gz: 286c11e9c2dea795607c3c35d4b662254609ae71b89f3e6d6a17729578900132
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ffe6fd28792ec03d9592ac3caf36268dba9c4710cefbe1ab9f4f3913eaf45f610beebaa6a7a183e4593b1e447ae69fd93df4094815231d15dae1b72c6fa1e59
|
7
|
+
data.tar.gz: 4e38c3c995f9efe86991d237d27c1b1c0ccc984d4b7870acb3fbd24f204e80881edd337211f47d705919556a3467db08836581982a68b5345f7edd4a2fc2e5d4
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -4,12 +4,13 @@ module GraphAttack
|
|
4
4
|
class RateLimit < GraphQL::Schema::FieldExtension
|
5
5
|
def resolve(object:, arguments:, **_rest)
|
6
6
|
rate_limited_field = object.context[rate_limited_key]
|
7
|
-
|
7
|
+
|
8
|
+
unless object.context.key?(rate_limited_key)
|
8
9
|
raise GraphAttack::Error,
|
9
|
-
"Missing :#{rate_limited_key}
|
10
|
+
"Missing :#{rate_limited_key} key on the GraphQL context"
|
10
11
|
end
|
11
12
|
|
12
|
-
if calls_exceeded_on_query?(rate_limited_field)
|
13
|
+
if rate_limited_field && calls_exceeded_on_query?(rate_limited_field)
|
13
14
|
return RateLimited.new('Query rate limit exceeded')
|
14
15
|
end
|
15
16
|
|
@@ -20,17 +21,15 @@ module GraphAttack
|
|
20
21
|
|
21
22
|
def key
|
22
23
|
on = "-#{options[:on]}" if options[:on]
|
24
|
+
|
23
25
|
"graphql-query-#{field.name}#{on}"
|
24
26
|
end
|
25
27
|
|
26
28
|
def calls_exceeded_on_query?(rate_limited_field)
|
27
29
|
rate_limit = Ratelimit.new(rate_limited_field, redis: redis_client)
|
28
30
|
rate_limit.add(key)
|
29
|
-
|
30
|
-
|
31
|
-
threshold: threshold,
|
32
|
-
interval: interval,
|
33
|
-
)
|
31
|
+
|
32
|
+
rate_limit.exceeded?(key, threshold: threshold, interval: interval)
|
34
33
|
end
|
35
34
|
|
36
35
|
def threshold
|
@@ -50,7 +49,7 @@ module GraphAttack
|
|
50
49
|
end
|
51
50
|
|
52
51
|
def redis_client
|
53
|
-
options[:redis_client] || Redis.
|
52
|
+
options[:redis_client] || Redis.new
|
54
53
|
end
|
55
54
|
|
56
55
|
def rate_limited_key
|
data/lib/graph_attack/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graph_attack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fanny Cheung
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-
|
12
|
+
date: 2022-12-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: graphql
|