Closed
Description
In graphql-ruby version 1.12.2 I can no longer parse queries when using Graphql::Backtrace. It seem to be a regression from when the multiplex batch loading was added #3264
I'm getting this error message when using Client.parse
:
Traceback (most recent call last):
5: from test.rb:60:in `<main>'
4: from /home/anton/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/graphql-client-0.16.0/lib/graphql/client.rb:194:in `parse'
3: from /home/anton/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/graphql-1.12.3/lib/graphql/static_validation/validator.rb:29:in `validate'
2: from /home/anton/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/graphql-1.12.3/lib/graphql/tracing.rb:67:in `trace'
1: from /home/anton/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/graphql-1.12.3/lib/graphql/tracing.rb:83:in `call_tracers'
/home/anton/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/graphql-1.12.3/lib/graphql/backtrace/tracer.rb:51:in `trace': undefined method `context' for nil:NilClass (NoMethodError)
The nil value is generated from query.multiplex
in the backtrace tracer on line 21 and is later used on line 51
This code should be sufficent to reproduce the issue.
gem 'graphql', '= 1.12.3'
gem 'graphql-client', '= 0.16.0'
require 'graphql'
require 'graphql/client'
class LocalExecution
def initialize(schema)
@schema = schema
end
def execute(
document:,
operation_name: nil,
variables: {},
context: {}
)
GraphQL::Query.new(
@schema,
document.to_query_string,
variables: variables,
context: validate_context(context),
operation_name: operation_name
).result
end
protected
def validate_context(context)
context
end
end
class TestType < GraphQL::Schema::Object
graphql_name 'Test'
field :test_field, String, null: false
def test_field
'Test test'
end
end
class QueryRoot < GraphQL::Schema::Object
graphql_name 'Query'
field :test, TestType, null: false
end
class Schema < GraphQL::Schema
query QueryRoot
use GraphQL::Backtrace # Works without GraphQL::Backtrace
end
Client = GraphQL::Client.new(
schema: Schema,
execute: LocalExecution.new(Schema)
)
Client.parse <<~GRAPHQL
query {
test {
testField
}
}
GRAPHQL
Metadata
Metadata
Assignees
Labels
No labels