Skip to content

Commit

Permalink
Use Field#owner for platform_field_key, for consistent keys
Browse files Browse the repository at this point in the history
  • Loading branch information
rmosolgo committed Feb 20, 2023
1 parent 4a5e131 commit a54d131
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/graphql/tracing/platform_tracing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def trace(key, data)

platform_key = if trace_field
context = data.fetch(:query).context
cached_platform_key(context, field, :field) { platform_field_key(data[:owner], field) }
cached_platform_key(context, field, :field) { platform_field_key(field.owner, field) }
else
nil
end
Expand Down
10 changes: 5 additions & 5 deletions spec/graphql/tracing/platform_trace_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def platform_resolve_type_key(type)

it "traces resolve_type and differentiates field calls on different types" do
scalar_schema = Class.new(Dummy::Schema) { trace_with(CustomPlatformTrace, trace_scalars: true) }
scalar_schema.execute(" { allEdible { __typename origin } }")
scalar_schema.execute(" { allEdible { __typename fatContent } }")
expected_trace = [
"em",
"am",
Expand All @@ -133,24 +133,24 @@ def platform_resolve_type_key(type)
"Cheese.authorized",
"DynamicFields.authorized",
"D._",
"C.o",
"C.f",
"Edible.resolve_type",
"Cheese.authorized",
"Cheese.authorized",
"DynamicFields.authorized",
"D._",
"C.o",
"C.f",
"Edible.resolve_type",
"Cheese.authorized",
"Cheese.authorized",
"DynamicFields.authorized",
"D._",
"C.o",
"C.f",
"Edible.resolve_type",
"Milk.authorized",
"DynamicFields.authorized",
"D._",
"M.o",
"E.f",
]

assert_equal expected_trace, CustomPlatformTrace::TRACE
Expand Down
48 changes: 48 additions & 0 deletions spec/graphql/tracing/platform_tracing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,54 @@ def platform_trace(platform_key, key, data)

assert_equal expected_trace, CustomPlatformTracer::TRACE
end

focus
it "traces resolve_type and differentiates field calls on different types" do
scalar_schema = Class.new(Dummy::Schema) { use(CustomPlatformTracer, trace_scalars: true) }

scalar_schema.execute(" { allEdible { __typename fatContent } }")
expected_trace = [
"em",
"am",
"l",
"p",
"v",
"aq",
"eq",
"Query.authorized",
"Q.a",
"Edible.resolve_type",
"Edible.resolve_type",
"Edible.resolve_type",
"Edible.resolve_type",
"eql",
"Edible.resolve_type",
"Cheese.authorized",
"Cheese.authorized",
"DynamicFields.authorized",
"D._",
"C.f",
"Edible.resolve_type",
"Cheese.authorized",
"Cheese.authorized",
"DynamicFields.authorized",
"D._",
"C.f",
"Edible.resolve_type",
"Cheese.authorized",
"Cheese.authorized",
"DynamicFields.authorized",
"D._",
"C.f",
"Edible.resolve_type",
"Milk.authorized",
"DynamicFields.authorized",
"D._",
"E.f",
]

assert_equal expected_trace, CustomPlatformTracer::TRACE
end
end

describe "by default, scalar fields are not traced" do
Expand Down

0 comments on commit a54d131

Please sign in to comment.