Skip to content

Regression in 2.5.12: execute_query_lazy no longer called on legacy tracer when dataloader plugin used #5450

@myronmarston

Description

@myronmarston

Describe the bug

Starting in 2.5.12, when a legacy tracer is used on a schema that also uses the GraphQL::Dataloader plugin, execute_query_lazy isn't called on the tracer.

Concretely, this causes exceptions for projects which also use the apollo-federation gem with tracing enabled.

Versions

graphql version: 2.5.12 and above
rails (or other framework): N/A
other applicable versions (graphql-batch, etc): N/A

GraphQL schema

Doesn't matter, but here's the one I'm using for the reproduction script below:

type Query {
  foo: Int
}

GraphQL query

Doesn't matter, but here's the query I'm using in the reproduction script below:

query { __typename }

Steps to reproduce

Put this script in a file:

require "bundler/inline"

gemfile do
  source "https://rubygems.org"
  gem "graphql", ENV.fetch("GRAPHQL_VERSION")
end

require "graphql"

class Application
  def initialize
    @schema = ::GraphQL::Schema.from_definition("type Query { foo: Int }", using: {::GraphQL::Dataloader => {}})
    @schema.tracer(Tracer)
  end

  def execute_query(query_string)
    ::GraphQL::Query.new(@schema, query_string).result
  end

  class Tracer
    def self.trace(key, metadata)
      puts "trace #{key}"
      yield
    end
  end
end

app = Application.new
result = app.execute_query("query { __typename }").to_h

puts "=" * 80
puts result

Then run it with GRAPHQL_VERSION=x.y.z ruby graphql_bug.rb to observe the behavior of different versions.

Expected behavior

I expect all trace events to fire like they do on 2.5.11:

$ GRAPHQL_VERSION=2.5.11 ruby graphql_bug.rb
`Schema.tracer(Application::Tracer)` is deprecated; use module-based `trace_with` instead. See: https://graphql-ruby.org/queries/tracing.html
  graphql_bug.rb:18:in 'Application#initialize'
trace execute_multiplex
trace analyze_multiplex
trace parse
trace validate
trace analyze_query
trace execute_query
trace authorized
trace authorized
trace execute_field
trace execute_query_lazy
================================================================================
{"data" => {"__typename" => "Query"}}

Actual behavior

The execute_query_lazy trace event does not fire on 2.5.12:

$ GRAPHQL_VERSION=2.5.12 ruby graphql_bug.rb
`Schema.tracer(Application::Tracer)` is deprecated; use module-based `trace_with` instead. See: https://graphql-ruby.org/queries/tracing.html
  graphql_bug.rb:18:in 'Application#initialize'
trace execute_multiplex
trace analyze_multiplex
trace parse
trace validate
trace analyze_query
trace execute_query
trace authorized
trace authorized
trace execute_field
================================================================================
{"data" => {"__typename" => "Query"}}

2.5.13 and 2.5.14 exhibit the same behavior.

Additional context

git bisect reveals commit 5ba154a (from #5422) as the culprit. Specifically, I think the removal of the call to multiplex.current_trace.execute_query_lazy from interpreter.rb causes this bug:

5ba154a#diff-c5478ea34f91a1b8e9084add8c080a3fba29e442515429c1d33ef2fa58131112L96

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions