1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
# frozen_string_literal: true
require "spec_helper"
describe GraphQL::Tracing::NotificationsTrace do
module NotificationsTraceTest
class Query < GraphQL::Schema::Object
field :int, Integer, null: false
def int
1
end
end
class Schema < GraphQL::Schema
query Query
end
end
describe "Observing" do
it "dispatchs the event to the notifications engine with suffixed key" do
dispatched_events = trigger_fake_notifications_tracer(NotificationsTraceTest::Schema).to_h
assert dispatched_events.length > 0
expected_event_keys = [
'execute_multiplex.graphql',
'analyze_multiplex.graphql',
(USING_C_PARSER ? 'lex.graphql' : nil),
'parse.graphql',
'validate.graphql',
'analyze_query.graphql',
'execute_query.graphql',
'authorized.graphql',
'execute_field.graphql',
'execute_query_lazy.graphql'
].compact
assert_equal expected_event_keys, dispatched_events.keys
dispatched_events.each do |event, payload|
assert event.end_with?(".graphql")
assert payload.is_a?(Hash)
end
end
end
def trigger_fake_notifications_tracer(schema)
dispatched_events = []
engine = Object.new
engine.define_singleton_method(:instrument) do |event, payload, &blk|
dispatched_events << [event, payload]
blk.call if blk
end
schema.trace_with GraphQL::Tracing::NotificationsTrace, engine: engine
schema.execute "query X { int }"
dispatched_events
end
end
|