Skip to content

Commit

Permalink
Merge pull request #5118 from Shopify/elvin/fix-trace-class-behaviour
Browse files Browse the repository at this point in the history
bug fix: respect options when using `trace_with` after `trace_class`.
  • Loading branch information
rmosolgo authored Oct 7, 2024
2 parents e409ef4 + 1baf0d7 commit 47cadd1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/graphql/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def trace_class(new_class = nil)
# re-apply them here
mods = trace_modules_for(:default)
mods.each { |mod| new_class.include(mod) }
new_class.include(DefaultTraceClass)
trace_mode(:default, new_class)
backtrace_class = Class.new(new_class)
backtrace_class.include(GraphQL::Backtrace::Trace)
Expand Down
20 changes: 20 additions & 0 deletions spec/graphql/tracing/trace_modes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,22 @@ class CustomBaseTraceSubclassSchema < CustomBaseTraceParentSchema
trace_with Module.new, mode: :special_with_base_class
end

class TraceWithWithOptionsSchema < GraphQL::Schema
class CustomTrace < GraphQL::Tracing::Trace
end

module OptionsTrace
def initialize(configured_option:, **_rest)
@configured_option = configured_option
super
end
end

trace_class CustomTrace
trace_with OptionsTrace, configured_option: :foo
end


it "uses the default trace class for default mode" do
assert_equal CustomBaseTraceParentSchema::CustomTrace, CustomBaseTraceParentSchema.trace_class_for(:default)
assert_equal CustomBaseTraceParentSchema::CustomTrace, CustomBaseTraceSubclassSchema.trace_class_for(:default).superclass
Expand All @@ -183,6 +199,10 @@ class CustomBaseTraceSubclassSchema < CustomBaseTraceParentSchema
assert_includes CustomBaseTraceSubclassSchema.trace_class_for(:special_with_base_class).ancestors, CustomBaseTraceParentSchema::CustomTrace
assert_kind_of CustomBaseTraceParentSchema::CustomTrace, CustomBaseTraceSubclassSchema.new_trace(mode: :special_with_base_class)
end

it "custom options are retained when using `trace_with` when there is already default tracer configured with `trace_class`" do
assert_equal({configured_option: :foo}, TraceWithWithOptionsSchema.trace_options_for(:default))
end
end

describe "custom default trace mode" do
Expand Down

0 comments on commit 47cadd1

Please sign in to comment.