Skip to content

Commit

Permalink
Add context for when to override api_version
Browse files Browse the repository at this point in the history
- add debug logging when the override is a NOOP
- improve documentation instructions

Co-authored-by: Kevin O'Sullivan <56687600+mkevinosullivan@users.noreply.github.com>
  • Loading branch information
ewalk153 and mkevinosullivan committed Jan 23, 2023
1 parent dc1eb75 commit 6ec3c19
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/usage/graphql.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ response = client.query(query: query, variables: variables)
# do something with the reponse
```

To experiment with prerelease features, pass the api_version unstable when initializing the client.
By default, the client uses the API version configured in `ShopifyAPI`. To use a different API version, set the optional `api_version` parameter. To experiment with prerelease API features, use `"unstable"` for the API version.

```ruby
client = ShopifyAPI::Clients::Graphql::Admin.new(session: session, api_version: "unstable")
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/graphql_storefront.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ response = client.query(query: query)
# do something with the returned data
```

To experiment with prerelease features, pass the api_version unstable when initializing the client.
By default, the client uses the API version configured in `ShopifyAPI`. To use a different API version, set the optional `api_version` parameter. To experiment with prerelease API features, use `"unstable"` for the API version.

```ruby
client = ShopifyAPI::Clients::Graphql::Storefront.new(shop_url, storefront_access_token, api_version: "unstable")
Expand Down
7 changes: 7 additions & 0 deletions lib/shopify_api/clients/graphql/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ class Client
def initialize(session:, base_path:, api_version: nil)
@http_client = T.let(HttpClient.new(session: session, base_path: base_path), HttpClient)
@api_version = T.let(api_version || Context.api_version, String)
if api_version
if api_version == Context.api_version
Context.logger.debug("Graphql client has a redundant API version override to the default #{Context.api_version}")
else
Context.logger.debug("Graphql client overriding default API version #{Context.api_version} with #{api_version}")
end
end
end

sig do
Expand Down
8 changes: 8 additions & 0 deletions lib/shopify_api/clients/rest/admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ class Admin < HttpClient
sig { params(session: T.nilable(Auth::Session), api_version: T.nilable(String)).void }
def initialize(session: nil, api_version: nil)
@api_version = T.let(api_version || Context.api_version, String)
if api_version
if api_version == Context.api_version
Context.logger.debug("Rest client has a redundant API version override to the default #{Context.api_version}")
else
Context.logger.debug("Rest client overriding default API version #{Context.api_version} with #{api_version}")
end
end

super(session: session, base_path: "/admin/api/#{@api_version}")
end

Expand Down

0 comments on commit 6ec3c19

Please sign in to comment.