diff --git a/lib/graphql/client.rb b/lib/graphql/client.rb index f064ca2..6fea76d 100644 --- a/lib/graphql/client.rb +++ b/lib/graphql/client.rb @@ -380,12 +380,12 @@ def query(definition, variables: {}, context: {}) error_payload = payload.merge(message: error["message"], error: error) ActiveSupport::Notifications.instrument("error.graphql", error_payload) end - Response.new( result, data: definition.new(data, Errors.new(errors, ["data"])), errors: Errors.new(errors), - extensions: extensions + extensions: extensions, + full_response: execute.respond_to?("last_response") ? execute.last_response : nil ) end diff --git a/lib/graphql/client/http.rb b/lib/graphql/client/http.rb index 700aaa8..7904ce1 100644 --- a/lib/graphql/client/http.rb +++ b/lib/graphql/client/http.rb @@ -45,6 +45,11 @@ def headers(_context) {} end + # Public: full reponse from last request + # + # Returns Hash. + attr_reader :last_response + # Public: Make an HTTP request for GraphQL query. # # Implements Client's "execute" adapter interface. @@ -71,6 +76,7 @@ def execute(document:, operation_name: nil, variables: {}, context: {}) request.body = JSON.generate(body) response = connection.request(request) + @last_response = response.to_hash case response when Net::HTTPOK, Net::HTTPBadRequest JSON.parse(response.body) diff --git a/lib/graphql/client/response.rb b/lib/graphql/client/response.rb index f262418..c00e250 100644 --- a/lib/graphql/client/response.rb +++ b/lib/graphql/client/response.rb @@ -31,12 +31,18 @@ class Response # Public: Hash of server specific extension metadata. attr_reader :extensions + # Public: Complete response hash returned from server. + # + # Returns Hash + attr_reader :full_response + # Internal: Initialize base class. - def initialize(hash, data: nil, errors: Errors.new, extensions: {}) + def initialize(hash, data: nil, errors: Errors.new, extensions: {}, full_response: nil) @original_hash = hash @data = data @errors = errors @extensions = extensions + @full_response = full_response end end end