graph_attack 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: de17498105231eb4dd5b5135cf8e7683680cafc409a66acf6fddbaa6f6735b36
4
- data.tar.gz: 60308e8ccff6fb80b4b5013975f9ea4903cb037b16997030635ace4557211f17
3
+ metadata.gz: 8e7c2758ed10d1304e998ecdfb980897aec795513e69eaef79cfcc7b0d42b76f
4
+ data.tar.gz: 286c11e9c2dea795607c3c35d4b662254609ae71b89f3e6d6a17729578900132
5
5
  SHA512:
6
- metadata.gz: 41706b8ea7768bf2d3220c6803f91c29a20640b177c8c443cf64a3462310dd939d4dfa92ffd2fd9f874bd6f256e50031ffbf893f5f4a58846fd7299191e12169
7
- data.tar.gz: 873abb6b86cb16f3575cff878cd2be3d0c47723b472b2949a6f4c0f9c6164996fa3b72142ce3e74a71952c5da89eac400a346a43607f174fa2e28862c5dd8d57
6
+ metadata.gz: 0ffe6fd28792ec03d9592ac3caf36268dba9c4710cefbe1ab9f4f3913eaf45f610beebaa6a7a183e4593b1e447ae69fd93df4094815231d15dae1b72c6fa1e59
7
+ data.tar.gz: 4e38c3c995f9efe86991d237d27c1b1c0ccc984d4b7870acb3fbd24f204e80881edd337211f47d705919556a3467db08836581982a68b5345f7edd4a2fc2e5d4
data/CHANGELOG.md CHANGED
@@ -1,6 +1,12 @@
1
1
  unreleased
2
2
  ----------
3
3
 
4
+ v2.2.0
5
+ ------
6
+
7
+ Feature:
8
+ - Skip throttling when rate limited field is nil (#19)
9
+
4
10
  v2.1.0
5
11
  ------
6
12
 
data/README.md CHANGED
@@ -58,6 +58,8 @@ class GraphqlController < ApplicationController
58
58
  end
59
59
  ```
60
60
 
61
+ If that key is `nil`, throttling will be disabled.
62
+
61
63
  ## Configuration
62
64
 
63
65
  ### Custom context key
@@ -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
- unless rate_limited_field
7
+
8
+ unless object.context.key?(rate_limited_key)
8
9
  raise GraphAttack::Error,
9
- "Missing :#{rate_limited_key} value on the GraphQL context"
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
- rate_limit.exceeded?(
30
- key,
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.current
52
+ options[:redis_client] || Redis.new
54
53
  end
55
54
 
56
55
  def rate_limited_key
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GraphAttack
4
- VERSION = '2.1.0'
4
+ VERSION = '2.2.0'
5
5
  end
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.1.0
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-08-07 00:00:00.000000000 Z
12
+ date: 2022-12-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: graphql