Skip to content

Commit

Permalink
Add guard clause to GraphQL gateway watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
y9v committed Sep 5, 2024
1 parent d620229 commit 31da3fb
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions lib/datadog/appsec/contrib/graphql/gateway/watcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,27 @@ def watch_multiplex(gateway = Instrumentation.gateway)

scope = AppSec::Scope.active_scope

if scope
AppSec::Reactive::Operation.new('graphql.multiplex') do |op|
GraphQL::Reactive::Multiplex.subscribe(op, scope.processor_context) do |result|
event = {
waf_result: result,
trace: scope.trace,
span: scope.service_entry_span,
multiplex: gateway_multiplex,
actions: result.actions
}
return stack.call(gateway_multiplex.arguments) unless scope

if scope.service_entry_span
scope.service_entry_span.set_tag('appsec.blocked', 'true') if result.actions.include?('block')
scope.service_entry_span.set_tag('appsec.event', 'true')
end
AppSec::Reactive::Operation.new('graphql.multiplex') do |op|
GraphQL::Reactive::Multiplex.subscribe(op, scope.processor_context) do |result|
event = {
waf_result: result,
trace: scope.trace,
span: scope.service_entry_span,
multiplex: gateway_multiplex,
actions: result.actions
}

scope.processor_context.events << event
if scope.service_entry_span
scope.service_entry_span.set_tag('appsec.blocked', 'true') if result.actions.include?('block')
scope.service_entry_span.set_tag('appsec.event', 'true')
end

block = GraphQL::Reactive::Multiplex.publish(op, gateway_multiplex)
scope.processor_context.events << event
end

block = GraphQL::Reactive::Multiplex.publish(op, gateway_multiplex)
end

next [nil, [[:block, event]]] if block
Expand Down

0 comments on commit 31da3fb

Please sign in to comment.