Skip to content

Commit 1d42e19

Browse files
committed
feat: Enable consumers to access the full response payload
Update the Response public API object to include full_response. this is non-breaking. Passing the full response from the executing object to the client is currently done via the client checking with the object, versus it being part of the response, In order to change this it requires changing the much more changes, as all the tests are using GraphQL::Schema for the execution of the graphql
1 parent 75fce88 commit 1d42e19

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

lib/graphql/client.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,12 +380,13 @@ def query(definition, variables: {}, context: {})
380380
error_payload = payload.merge(message: error["message"], error: error)
381381
ActiveSupport::Notifications.instrument("error.graphql", error_payload)
382382
end
383-
383+
384384
Response.new(
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.respond_to?("last_response") ? execute.last_response : nil
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)