graphql-client
graphql-client copied to clipboard
0.17.0 breaks as_json/to_json on graphql response
It seems like 0.17.0 introduces a SystemStackError when to_json or as_json is done on the graphql response see below for stacktrace:
res.data.to_json
Traceback (most recent call last):
16: from /usr/local/bundle/gems/activesupport-6.1.4.1/lib/active_support/core_ext/object/json.rb:174:in `as_json'
15: from /usr/local/bundle/gems/activesupport-6.1.4.1/lib/active_support/core_ext/object/json.rb:174:in `each'
14: from /usr/local/bundle/gems/activesupport-6.1.4.1/lib/active_support/core_ext/object/json.rb:175:in `block in as_json'
13: from /usr/local/bundle/gems/activesupport-6.1.4.1/lib/active_support/core_ext/object/json.rb:58:in `as_json'
12: from /usr/local/bundle/gems/activesupport-6.1.4.1/lib/active_support/core_ext/object/json.rb:174:in `as_json'
11: from /usr/local/bundle/gems/activesupport-6.1.4.1/lib/active_support/core_ext/object/json.rb:174:in `each'
10: from /usr/local/bundle/gems/activesupport-6.1.4.1/lib/active_support/core_ext/object/json.rb:175:in `block in as_json'
9: from /usr/local/bundle/gems/activesupport-6.1.4.1/lib/active_support/core_ext/object/json.rb:58:in `as_json'
8: from /usr/local/bundle/gems/activesupport-6.1.4.1/lib/active_support/core_ext/object/json.rb:174:in `as_json'
7: from /usr/local/bundle/gems/activesupport-6.1.4.1/lib/active_support/core_ext/object/json.rb:174:in `each'
6: from /usr/local/bundle/gems/activesupport-6.1.4.1/lib/active_support/core_ext/object/json.rb:175:in `block in as_json'
5: from /usr/local/bundle/gems/activesupport-6.1.4.1/lib/active_support/core_ext/object/json.rb:174:in `as_json'
4: from /usr/local/bundle/gems/activesupport-6.1.4.1/lib/active_support/core_ext/object/json.rb:174:in `each'
3: from /usr/local/bundle/gems/activesupport-6.1.4.1/lib/active_support/core_ext/object/json.rb:175:in `block in as_json'
2: from /usr/local/bundle/gems/activesupport-6.1.4.1/lib/active_support/core_ext/object/json.rb:58:in `as_json'
1: from /usr/local/bundle/gems/activesupport-6.1.4.1/lib/active_support/core_ext/object/instance_variables.rb:15:in `instance_values'
SystemStackError (stack level too deep)
Using to_h on the response still works though on both versions.
After a quick investigation, breaking change seems to have been introduced in this commit https://github.com/github/graphql-client/commit/01fcb5891ff5782d893ba4bac9840c3875a3440c
@navied is there any updates on this issue?
This error happens because now ObjectClass
class has definer
variable that has circular references.
response.data.instance_values["definer"].instance_values["klass"].instance_values["null_type"].instance_values["of_klass"].instance_values["null_type"].instance_values["of_klass"]
https://github.com/github/graphql-client/blob/d19333d9587d7b187bba1f2339dc09a52067f8be/lib/graphql/client/schema/object_type.rb#L177-L187
ActiveSupport(as_json
) tries to call instance_values
if object
doesn't have to_hash
methods. Therefore this SystemStackError
happnes.
class Object
def as_json(options = nil) # :nodoc:
if respond_to?(:to_hash)
to_hash.as_json(options)
else
instance_values.as_json(options)
end
end
end
https://github.com/rails/rails/blob/3fcadfb7cf95e4a7e0bf9795019d4de212de97b0/activesupport/lib/active_support/core_ext/object/json.rb#L58-L66
I'm trying to fix this in this PR https://github.com/github/graphql-client/pull/281