ashkan18 / graphlient

Ruby GraphQL Client
MIT License
249 stars 43 forks source link

Make JSON parser swappable #9

Open dblock opened 6 years ago

dblock commented 6 years ago

Want to be able to use multi_json or OJ.

yuki24 commented 6 years ago

Both Ruby and Rails allow for swapping the default JSON parser:

require 'json'

JSON.parser
# => JSON::Ext::Parser

JSON.parse '{"foo":1}'
# => {"foo"=>1}

JSON.parser = nil
JSON.parse '{"foo":1}'
# => NoMethodError: undefined method `new' for nil:NilClass

require 'oj'
JSON.parser = Oj
JSON.parse '{"foo":1}'
# => {"foo"=>1}

Oj even has its own mechanism to inject itself to Rails:

require 'active_support/json/encoding'

ActiveSupport::JSON::Encoding.json_encoder
# => ActiveSupport::JSON::Encoding::JSONGemEncoder

require 'oj'
Oj.optimize_rails

ActiveSupport::JSON::Encoding.json_encoder
# => Oj::Rails::Encoder

So I'm not sure if it makes sense for this gem to depend on third-party libraries.