Skip to content

Commit c029d8a

Browse files
authored
Merge pull request #1327 from Shopify/add_debug_graphql_option
Add debug option to GraphQL requests
2 parents ebf1b60 + 2b7c1f5 commit c029d8a

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Note: For changes to the API, see https://shopify.dev/changelog?filter=api
44

55
## Unreleased
66

7+
- [#1327](https://github.com/Shopify/shopify-api-ruby/pull/1327) Support `?debug=true` parameter in GraphQL client requests
8+
79
## 14.4.0
810

911
- [#1325](https://github.com/Shopify/shopify-api-ruby/pull/1325) Add support for 2024-07 API version

lib/shopify_api/clients/graphql/client.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,24 @@ def initialize(session:, base_path:, api_version: nil)
2929
headers: T.nilable(T::Hash[T.any(Symbol, String), T.untyped]),
3030
tries: Integer,
3131
response_as_struct: T.nilable(T::Boolean),
32+
debug: T::Boolean,
3233
).returns(HttpResponse)
3334
end
34-
def query(query:, variables: nil, headers: nil, tries: 1, response_as_struct: Context.response_as_struct)
35+
def query(
36+
query:,
37+
variables: nil,
38+
headers: nil,
39+
tries: 1,
40+
response_as_struct: Context.response_as_struct,
41+
debug: false
42+
)
3543
body = { query: query, variables: variables }
44+
search_params = debug ? "?debug=true" : ""
45+
3646
@http_client.request(
3747
HttpRequest.new(
3848
http_method: :post,
39-
path: "#{@api_version}/graphql.json",
49+
path: "#{@api_version}/graphql.json#{search_params}",
4050
body: body,
4151
query: nil,
4252
extra_headers: headers,

lib/shopify_api/clients/graphql/storefront.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,20 @@ def initialize(shop, storefront_access_token = nil, private_token: nil, public_t
4646
headers: T.nilable(T::Hash[T.any(Symbol, String), T.untyped]),
4747
tries: Integer,
4848
response_as_struct: T.nilable(T::Boolean),
49+
debug: T::Boolean,
4950
).returns(HttpResponse)
5051
end
51-
def query(query:, variables: nil, headers: {}, tries: 1, response_as_struct: Context.response_as_struct)
52+
def query(
53+
query:,
54+
variables: nil,
55+
headers: {},
56+
tries: 1,
57+
response_as_struct: Context.response_as_struct,
58+
debug: false
59+
)
5260
T.must(headers).merge!({ @storefront_auth_header => @storefront_access_token })
5361
super(query: query, variables: variables, headers: headers, tries: tries,
54-
response_as_struct: response_as_struct)
62+
response_as_struct: response_as_struct, debug: debug)
5563
end
5664
end
5765
end

test/test_helpers/graphql_client.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,25 @@ def test_can_override_api_version
8383

8484
@client.query(query: query, variables: variables)
8585
end
86+
87+
def test_can_make_debug_requests
88+
query = <<~QUERY
89+
{
90+
shop {
91+
name
92+
}
93+
}
94+
QUERY
95+
body = { query: query, variables: nil }
96+
success_body = { "success" => true }
97+
response_headers = { "content-type" => "application/json" }
98+
99+
stub_request(:post, "https://test-shop.myshopify.com/#{@path}/#{ShopifyAPI::Context.api_version}/graphql.json?debug=true")
100+
.with(body: body, headers: @expected_headers)
101+
.to_return(body: success_body.to_json, headers: response_headers)
102+
103+
response = @client.query(query: query, debug: true)
104+
assert_equal(success_body, response.body)
105+
end
86106
end
87107
end

0 commit comments

Comments
 (0)