Class: GraphAttack::RateLimit

Inherits:
GraphQL::Schema::FieldExtension
  • Object
show all
Defined in:
lib/graph_attack/rate_limit.rb

Instance Method Summary collapse

Instance Method Details

#resolve(object:, arguments:, **_rest) {|object, arguments| ... } ⇒ Object

Yields:

  • (object, arguments)

Raises:



5
6
7
8
9
10
11
12
# File 'lib/graph_attack/rate_limit.rb', line 5

def resolve(object:, arguments:, **_rest)
  ip = object.context[:ip]
  raise GraphAttack::Error, 'Missing :ip value on the GraphQL context' unless ip

  return RateLimited.new('Query rate limit exceeded') if calls_exceeded_on_query?(ip)

  yield(object, arguments)
end