Skip to content

Commit

Permalink
Merge pull request #3342 from rmosolgo/fix-backtrace-tracer
Browse files Browse the repository at this point in the history
Fix backtrace multiplex tracing without execute
  • Loading branch information
Robert Mosolgo authored Feb 16, 2021
2 parents a0b6e48 + 9c65b9b commit 066cef3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/graphql/backtrace/tracer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ def trace(key, metadata)
end

if push_data && multiplex
multiplex.context[:graphql_backtrace_contexts][push_key] = push_data
push_storage = multiplex.context[:graphql_backtrace_contexts] ||= {}
push_storage[push_key] = push_data
multiplex.context[:last_graphql_backtrace_context] = push_data
end

if key == "execute_multiplex"
multiplex_context = metadata[:multiplex].context
multiplex_context[:graphql_backtrace_contexts] = {}
begin
yield
rescue StandardError => err
Expand Down
28 changes: 28 additions & 0 deletions spec/graphql/backtrace_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,32 @@ def assert_backtrace_includes(backtrace, file:, method:)
res = backtrace_schema.validate("{ __typename }")
assert_equal [], res
end

it "works with stand-alone analysis" do
example_analyzer = Class.new(GraphQL::Analysis::AST::Analyzer) do
def result
:finished
end
end
query = GraphQL::Query.new(backtrace_schema, "{ __typename }")
result = GraphQL::Analysis::AST.analyze_query(query, [example_analyzer])
assert_equal [:finished], result
end

it "works with multiplex analysis" do
example_analyzer = Class.new(GraphQL::Analysis::AST::Analyzer) do
def result
:finished
end
end
query = GraphQL::Query.new(backtrace_schema, "{ __typename }")
multiplex = GraphQL::Execution::Multiplex.new(
schema: schema,
queries: [query],
context: {},
max_complexity: nil,
)
result = GraphQL::Analysis::AST.analyze_multiplex(multiplex, [example_analyzer])
assert_equal [:finished], result
end
end

0 comments on commit 066cef3

Please sign in to comment.