Skip to content

Commit 202b5be

Browse files
committed
feat: Enable consumers to access the full response payload
create end user public api in the response object called full_response, this is non breaking and additive feature that should not need to change. Propergating it from internal class with @last_response attribute, we can change this to be in the return object of execute, but i would need to know all the places that i need to change.
1 parent 75fce88 commit 202b5be

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

lib/graphql/client.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,8 @@ def query(definition, variables: {}, context: {})
385385
result,
386386
data: definition.new(data, Errors.new(errors, ["data"])),
387387
errors: Errors.new(errors),
388-
extensions: extensions
388+
extensions:,
389+
full_response: execute.last_response
389390
)
390391
end
391392

lib/graphql/client/http.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ def headers(_context)
4545
{}
4646
end
4747

48+
# Public: full reponse from last request
49+
#
50+
# Returns Hash.
51+
attr_reader :last_response
52+
4853
# Public: Make an HTTP request for GraphQL query.
4954
#
5055
# Implements Client's "execute" adapter interface.
@@ -71,6 +76,7 @@ def execute(document:, operation_name: nil, variables: {}, context: {})
7176
request.body = JSON.generate(body)
7277

7378
response = connection.request(request)
79+
@last_response = response.to_hash
7480
case response
7581
when Net::HTTPOK, Net::HTTPBadRequest
7682
JSON.parse(response.body)

lib/graphql/client/response.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,18 @@ class Response
3131
# Public: Hash of server specific extension metadata.
3232
attr_reader :extensions
3333

34+
# Public: Complete response hash returned from server.
35+
#
36+
# Returns Hash
37+
attr_reader :full_response
38+
3439
# Internal: Initialize base class.
35-
def initialize(hash, data: nil, errors: Errors.new, extensions: {})
40+
def initialize(hash, data: nil, errors: Errors.new, extensions: {}, full_response: nil)
3641
@original_hash = hash
3742
@data = data
3843
@errors = errors
3944
@extensions = extensions
45+
@full_response = full_response
4046
end
4147
end
4248
end

0 commit comments

Comments
 (0)