graphql-client icon indicating copy to clipboard operation
graphql-client copied to clipboard

Feature: print raw JSON received

Open davidw opened this issue 6 years ago • 3 comments

It'd be handy to have a way to print out the raw JSON from the response, for debugging purposes.

Looks like it'd be pretty easy to add that, depending on the preferred method for doing so.

davidw avatar Jun 06 '19 21:06 davidw

Is this not covered by the original_hash method?

e.g.

require 'graphql'
require 'graphql/client'
require 'graphql/client/http'

url = 'https://gitlab.com/api/graphql'
http = GraphQL::Client::HTTP.new(url)
schema = GraphQL::Client.load_schema(http)
client = GraphQL::Client.new(schema:schema, execute: http)

QUERY = client.parse "query($id: ID!) { group(fullPath: $id) { id } }"
client.query(QUERY, variables: {}).original_hash
# => {"errors"=>[{"message"=>"Variable id of type ID! was provided invalid value", "locations"=>[{"line"=>1, "column"=>14}], "value"=>nil, "problems"=>[{"path"=>[], "explanation"=>"Expected value to not be null"}]}]} 

ericyd avatar Aug 01 '19 16:08 ericyd

Close enough I guess, but it still might be nice to be able to view the actual JSON?

davidw avatar Aug 01 '19 16:08 davidw

Hm, I'm not sure I get what the difference is. For the above request, what kind of JSON are you expecting? Could you use JSON.generate or JSON.pretty_generate to get "true JSON" format?

ericyd avatar Aug 01 '19 18:08 ericyd