Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/graphql/tracing/perfetto_trace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def self.included(_trace_class)
DA_FETCH_KEYS_IID => "fetch keys",
}

ANON_CLASS_NAME = "(anonymous)"

DEBUG_INSPECT_CATEGORY_IIDS = [15]
DA_DEBUG_INSPECT_CLASS_IID = 16
DEBUG_INSPECT_EVENT_NAME_IID = 17
Expand Down Expand Up @@ -118,7 +120,7 @@ def initialize(active_support_notifications_pattern: nil, save_profile: false, *
}

@source_name_iids = Hash.new do |h, source_class|
h[source_class] = @interned_event_name_iids[source_class.name]
h[source_class] = @interned_event_name_iids[source_class.name || ANON_CLASS_NAME]
end.compare_by_identity

@auth_name_iids = Hash.new do |h, graphql_type|
Expand All @@ -144,7 +146,7 @@ def initialize(active_support_notifications_pattern: nil, save_profile: false, *
end

@class_name_iids = Hash.new do |h, k|
h[k] = @interned_da_string_values[k.name]
h[k] = @interned_da_string_values[k.name || ANON_CLASS_NAME]
end.compare_by_identity

@starting_objects = GC.stat(:total_allocated_objects)
Expand Down Expand Up @@ -682,7 +684,7 @@ def payload_to_debug(k, v, iid: nil, intern_value: false)
when GraphQL::Schema::InputObject
payload_to_debug(k, v.to_h, iid: iid, intern_value: intern_value)
else
class_name_iid = @interned_da_string_values[(v.class.name || "(anonymous)")]
class_name_iid = @interned_da_string_values[(v.class.name || ANON_CLASS_NAME)]
da = [
debug_annotation(DA_DEBUG_INSPECT_CLASS_IID, :string_value_iid, class_name_iid),
]
Expand Down
12 changes: 9 additions & 3 deletions spec/graphql/tracing/detailed_trace_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@

describe GraphQL::Tracing::DetailedTrace do
class SamplerSchema < GraphQL::Schema
class Query < GraphQL::Schema::Object
field :truthy, Boolean, fallback_value: true, resolve_static: true
query = Class.new(GraphQL::Schema::Object) do
graphql_name "Query"
field :truthy, GraphQL::Types::Boolean, fallback_value: true, resolve_static: true
def self.truthy(ctx); true; end
end

query(Query)
query(query)
use GraphQL::Tracing::DetailedTrace, memory: true
def self.detailed_trace?(query)
if query.is_a?(GraphQL::Execution::Multiplex)
Expand Down Expand Up @@ -43,6 +44,11 @@ def exec_multiplex(...)
assert_equal 1, SamplerSchema.detailed_trace.traces.size
end

it "works with introspection on anonymous classes" do
assert_nil SamplerSchema.query.name
assert exec_query("{ __schema { types { name } } }")
end

it "calls through to storage for access methods" do
exec_query("{ truthy }")
id = SamplerSchema.detailed_trace.traces.first.id
Expand Down
Loading