Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Make the tracer work with the new interpreter runtime #59

Merged
merged 6 commits into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
14 changes: 8 additions & 6 deletions lib/apollo-federation/tracing/tracer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def self.execute_query_lazy(data, &block)
# because we don't have the error `location` here.
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
def self.execute_field(data, &block)
context = data.fetch(:context) || data.fetch(:query).context
context = data.fetch(:context, nil) || data.fetch(:query).context
return block.call unless context && context[:tracing_enabled]

start_time_nanos = Process.clock_gettime(Process::CLOCK_MONOTONIC, :nanosecond)
Expand All @@ -116,16 +116,18 @@ def self.execute_field(data, &block)

end_time_nanos = Process.clock_gettime(Process::CLOCK_MONOTONIC, :nanosecond)

# interpreter runtime
# legacy runtime
if data.include?(:context)
path = context.path
field_name = context.field.graphql_name
field_type = context.field.type.to_s
parent_type = context.parent_type.graphql_name
else # legacy runtime
else # interpreter runtime
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we got the legacy and new interpreter the wrong way round. I get into this branch

path = data.fetch(:path)
field_name = data.fetch(:field).graphql_name
field_type = data.fetch(:field).type.unwrap.graphql_name
field = data.fetch(:field)
field_name = field.graphql_name
field_type = field.type.unwrap.graphql_name
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call to write a spec @grxy . This has always been broken by the test caught it. The graphql_name of the type doesn't include whether it's nullable, hence the need to check the field

field_type = field_type + '!' if field.type.non_null?
parent_type = data.fetch(:owner).graphql_name
end

Expand All @@ -147,7 +149,7 @@ def self.execute_field(data, &block)
# Optional Step 3:
# Overwrite the end times on the trace node if the resolver was lazy.
def self.execute_field_lazy(data, &block)
context = data.fetch(:context) || data.fetch(:query).context
context = data.fetch(:context, nil) || data.fetch(:query).context
return block.call unless context && context[:tracing_enabled]

begin
Expand Down
Loading