Ruby's built in methods get called rather than the accessor methods on query responses in 0.17.0
We noticed that Ruby's built in methods get called rather than the accessor methods defined by this gem on the query response from 0.17.0.
This behaviour has come up after https://github.com/github/graphql-client/pull/252. To reduce the memory footprint for large queries, rather than defining method definitions for all the fields, graphql-client checks if the method is missing and then define it when the field is accessed.
This comes up for a method that is already defined within the ancestors such as Object#method or Kernel#test
In this case, graphql-client won’t call respond_to_missing? because a method with such a name exists from one of the ancestors. Only if the method doesn’t exist will respond_to_missing? be called and then check if its name is in one two sets.
I've written a script to demonstrate the error across two versions of the gem
require "bundler/inline"
gemfile do
source 'https://rubygems.org'
if ENV["BEFORE"]
puts "using graphql-client 0.16.0"
gem "graphql-client", "0.16.0"
elsif ENV["AFTER"]
puts "using graphql-client 0.17.0"
gem "graphql-client", "0.17.0"
else
raise "Pass BEFORE=1 or AFTER=1"
end
end
class Query < GraphQL::Schema::Object
field :things, String, null: false
def things
"things"
end
field :method, String, null: false
def method
"method"
end
end
class Schema < GraphQL::Schema
query Query
end
client = GraphQL::Client.new(schema: Schema, execute: Schema)
QUERY = client.parse(<<-'GRAPHQL')
query {
things
method
}
GRAPHQL
result = client.query(QUERY)
p result.data.method