Skip to content

Commit

Permalink
fix: Make the tracer work with the new interpreter runtime (#59)
Browse files Browse the repository at this point in the history
* Default to nil to run the or conditional

* Another case where we fetch context without going into the conditional

* Use tests to produce the right code

* Don't assign

* Fix style offenses

* Update specs again, got the way examples work wrong
  • Loading branch information
daemonsy authored Mar 25, 2020
1 parent baa3931 commit de4caf0
Show file tree
Hide file tree
Showing 2 changed files with 263 additions and 241 deletions.
13 changes: 7 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,17 @@ 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
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.to_type_signature
parent_type = data.fetch(:owner).graphql_name
end

Expand All @@ -147,7 +148,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

0 comments on commit de4caf0

Please sign in to comment.