Skip to content

Commit

Permalink
Write a failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
rmosolgo committed Jul 30, 2024
1 parent f0823d2 commit 70027f5
Showing 1 changed file with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -375,14 +375,26 @@ def execute_query(query:)
end

it 'works with other trace modules' do
custom_trace_schema = Class.new(SomeGraphQLAppSchema)
custom_trace_schema.trace_with(CustomTrace)
[GraphQL::Schema, SomeOtherGraphQLAppSchema, SomeGraphQLAppSchema].each(&:_reset_tracer_for_testing)
instrumentation.instance_variable_set(:@installed, false)

custom_trace_schema = Class.new(GraphQL::Schema) do
query(Class.new(GraphQL::Schema::Object) do
graphql_name 'Query'
field :int, Integer, fallback_value: 5
end)

trace_with(CustomTrace)
end

instrumentation.install({ schemas: [custom_trace_schema] })
res = custom_trace_schema.execute('{ vehicle { __typename } }')
res = custom_trace_schema.execute('{ int }')
assert_equal 5, res['data']['int'], 'The query ran successfully'

assert res.context[:custom_trace_execute_query_ran], 'The custom execute_query hook ran'
assert res.query.multiplex.context[:custom_trace_execute_multiplex_ran], 'The custom execute_multiplex hook ran'

assert_equal 'Car', res['data']['vehicle']['__typename']
assert res.context[:custom_trace_execute_query_ran]
assert res.query.multiplex.context[:custom_trace_execute_multiplex_ran]
assert spans.find { |s| s.name == 'graphql.execute_query' }, 'OpenTelementry ran'
end
end
end
Expand Down

0 comments on commit 70027f5

Please sign in to comment.