shopify_api-graphql-tiny 1.0.2 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.env.template +2 -1
- data/.github/workflows/ci.yml +4 -3
- data/Changes +9 -0
- data/README.md +56 -3
- data/lib/shopify_api/graphql/tiny/version.rb +1 -1
- data/lib/shopify_api/graphql/tiny.rb +32 -9
- data/shopify_api-graphql-tiny.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2d550d3eaf0d6ac8c9701e0e5d140dffe49fdf43cdb0d709b9e0d94042b7527c
|
|
4
|
+
data.tar.gz: a588f78468f1bcc1208229d0173648cfeb6f29fb93a64869e1b6e84722bfc920
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fe4aa237dc1d694b541b33b400fdf5890001364a22e9cc81f84ab2ca27a74b795795072ed887dd40b5391d1a089901dec5b445ffaa1071e7865eb02dd99508dd
|
|
7
|
+
data.tar.gz: 8b8249432936e22fa01679d0755ad97b7f63383b440c9b5c8b9c0f8f198222e937c7a5b139e9fb42ecef5d595ef1ed80d28e92b980dd10e632f18c563239e8e8
|
data/.env.template
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
# Must be full domain as it's used in test assertions
|
|
9
9
|
SHOPIFY_DOMAIN=
|
|
10
|
-
|
|
10
|
+
SHOPIFY_ADMIN_TOKEN=
|
|
11
|
+
SHOPIFY_STOREFRONT_TOKEN=
|
|
11
12
|
|
|
12
13
|
# Will result in the creation of a metadafield on the customer. write_customers permission required
|
|
13
14
|
SHOPIFY_CUSTOMER_ID=
|
data/.github/workflows/ci.yml
CHANGED
|
@@ -9,16 +9,17 @@ jobs:
|
|
|
9
9
|
runs-on: ubuntu-latest
|
|
10
10
|
env:
|
|
11
11
|
SHOPIFY_DOMAIN: "${{ secrets.SHOPIFY_DOMAIN }}"
|
|
12
|
-
|
|
12
|
+
SHOPIFY_ADMIN_TOKEN: "${{ secrets.SHOPIFY_ADMIN_TOKEN }}"
|
|
13
|
+
SHOPIFY_STOREFRONT_TOKEN: "${{ secrets.SHOPIFY_STOREFRONT_TOKEN }}"
|
|
13
14
|
SHOPIFY_CUSTOMER_ID: "${{ secrets.SHOPIFY_CUSTOMER_ID }}"
|
|
14
15
|
SHOPIFY_PRODUCT_ID: "${{ secrets.SHOPIFY_PRODUCT_ID }}"
|
|
15
16
|
|
|
16
17
|
strategy:
|
|
17
18
|
matrix:
|
|
18
|
-
ruby: ['3.4', '3.3', '3.2', '3.1', '3.0', '2.7']
|
|
19
|
+
ruby: ['4.0', '3.4', '3.3', '3.2', '3.1', '3.0', '2.7']
|
|
19
20
|
|
|
20
21
|
steps:
|
|
21
|
-
- uses: actions/checkout@
|
|
22
|
+
- uses: actions/checkout@v7
|
|
22
23
|
- uses: ruby/setup-ruby@v1
|
|
23
24
|
with:
|
|
24
25
|
bundler-cache: true
|
data/Changes
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
2026-11-17 v1.1.1
|
|
2
|
+
--------------------
|
|
3
|
+
* Add support for Pager#cursor to expose the current page's cursor
|
|
4
|
+
* Don't mutate a pagination caller's variable argument
|
|
5
|
+
|
|
6
|
+
2026-06-25 v1.1.0
|
|
7
|
+
--------------------
|
|
8
|
+
* Add support for requests against the storefront API
|
|
9
|
+
|
|
1
10
|
2026-06-23 v1.0.2
|
|
2
11
|
--------------------
|
|
3
12
|
* Add :raise_on_warnings option to raise a WarningError when a response contains warnings
|
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# ShopifyAPI::GraphQL::Tiny
|
|
2
2
|
|
|
3
|
-
Lightweight, no-nonsense, Shopify GraphQL
|
|
3
|
+
Lightweight, no-nonsense, Shopify Admin & Storefront GraphQL API client with built-in pagination and retry
|
|
4
4
|
|
|
5
5
|
[](https://github.com/ScreenStaring/shopify_api-graphql-tiny/actions)
|
|
6
6
|
|
|
@@ -74,6 +74,30 @@ GQL
|
|
|
74
74
|
p result.dig("data", "customerUpdate", "userErrors")
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
+
### Storefront API
|
|
78
|
+
|
|
79
|
+
By default requests are made against the Admin API.
|
|
80
|
+
To make requests against the Storefront API use the `:storefront => true` option:
|
|
81
|
+
|
|
82
|
+
```rb
|
|
83
|
+
gql = ShopifyAPI::GraphQL::Tiny.new("my-shop", token, :storefront => true)
|
|
84
|
+
result = gql.execute(<<-GQL, :id => your_gid)
|
|
85
|
+
query($id: ID!) {
|
|
86
|
+
product(id: $id) {
|
|
87
|
+
selectedOrFirstAvailableVariant {
|
|
88
|
+
id
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
GQL
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
You can set the storefront buyer's IP address (`Shopify-Storefront-Buyer-IP` HTTP header) via the `:ip` option:
|
|
96
|
+
|
|
97
|
+
```rb
|
|
98
|
+
gql = ShopifyAPI::GraphQL::Tiny.new("my-shop", token, :storefront => true, :ip => request.remote_ip)
|
|
99
|
+
```
|
|
100
|
+
|
|
77
101
|
### Automatically Retrying Failed Requests
|
|
78
102
|
|
|
79
103
|
There are 2 types of retries: 1) request is rate-limited by Shopify 2) request fails due to an exception or non-200 HTTP response.
|
|
@@ -129,6 +153,24 @@ These can be overridden globally (by assigning to the constant) or per instance:
|
|
|
129
153
|
gql = ShopifyAPI::GraphQL::Tiny.new(shop, token, :retry => [SystemCallError, "500"])
|
|
130
154
|
```
|
|
131
155
|
|
|
156
|
+
Also see [Token Expiry](#token-expiry).
|
|
157
|
+
|
|
158
|
+
### Token Expiry
|
|
159
|
+
|
|
160
|
+
`ShopifyAPI::GraphQL::Tiny` does not handle refreshing expired or expiring tokens. Remember, it's tiny!
|
|
161
|
+
To handle token refresh and migration use [`ShopifyAPI::GraphQL::Request`](https://github.com/ScreenStaring/shopify_api-graphql-request)
|
|
162
|
+
which is a higher-level wrapper around this class.
|
|
163
|
+
|
|
164
|
+
### Timeouts
|
|
165
|
+
|
|
166
|
+
Use the `:open_timeout` and `:read_timeout` options. They apply to the initial request and any retries:
|
|
167
|
+
|
|
168
|
+
```rb
|
|
169
|
+
gql = ShopifyAPI::GraphQL::Tiny.new("my-shop", token, :open_timeout => 5, :read_timeout => 15)
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Both default to `Net::HTTP`'s defaults.
|
|
173
|
+
|
|
132
174
|
#### Disabling Automatic Retry
|
|
133
175
|
|
|
134
176
|
To disable retries set the `:retry` option to `false`:
|
|
@@ -167,6 +209,18 @@ results = pager.execute(query, :foo => 123)
|
|
|
167
209
|
results.each { |page| ... }
|
|
168
210
|
```
|
|
169
211
|
|
|
212
|
+
`pager` contains a `#cursor` method that returns the GraphQL pagination cursor's current value. It is updated after each iteration:
|
|
213
|
+
```rb
|
|
214
|
+
results = pager.execute(query, :foo => 123)
|
|
215
|
+
results.each do |page|
|
|
216
|
+
puts "Cursor: #{pager.cursor}"
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
pager.execute(query, :foo => 123).each do |page|
|
|
220
|
+
puts "Cursor: #{pager.cursor}"
|
|
221
|
+
end
|
|
222
|
+
```
|
|
223
|
+
|
|
170
224
|
#### `after` Pagination
|
|
171
225
|
|
|
172
226
|
To use `after` pagination, i.e., to paginate forward, your query must:
|
|
@@ -311,7 +365,6 @@ bundle exec rake rate_limit SHOPIFY_DOMAIN=your-domain SHOPIFY_TOKEN=your-token
|
|
|
311
365
|
|
|
312
366
|
- [`ShopifyAPI::GraphQL::Request`](https://github.com/ScreenStaring/shopify_api-graphql-request) - A higher-level wrapper around this class with improved exception handling and `:snake_case` hash key conversion
|
|
313
367
|
- [Shopify Dev Tools](https://github.com/ScreenStaring/shopify-dev-tools) - Command-line program to assist with the development and/or maintenance of Shopify apps and stores
|
|
314
|
-
- [Shopify ID Export](https://github.com/ScreenStaring/shopify_id_export/) - Dump Shopify product and variant IDs —along with other identifiers— to a CSV or JSON file
|
|
315
368
|
- [`TinyGID`](https://github.com/sshaw/tiny_gid/) - Build Global ID (gid://) URI strings from scalar values
|
|
316
369
|
|
|
317
370
|
## License
|
|
@@ -320,4 +373,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
|
320
373
|
|
|
321
374
|
---
|
|
322
375
|
|
|
323
|
-
Made by [ScreenStaring](
|
|
376
|
+
Made by [ScreenStaring](https://screenstaring.com)
|
|
@@ -8,7 +8,7 @@ require "shopify_api/graphql/tiny/version"
|
|
|
8
8
|
module ShopifyAPI
|
|
9
9
|
module GraphQL
|
|
10
10
|
##
|
|
11
|
-
# Lightweight, no-nonsense, Shopify GraphQL Admin API client with built-in pagination and retry
|
|
11
|
+
# Lightweight, no-nonsense, Shopify GraphQL Admin/Storefront API client with built-in pagination and retry
|
|
12
12
|
#
|
|
13
13
|
class Tiny
|
|
14
14
|
Error = Class.new(StandardError)
|
|
@@ -45,6 +45,8 @@ module ShopifyAPI
|
|
|
45
45
|
SHOPIFY_DOMAIN = ".myshopify.com"
|
|
46
46
|
|
|
47
47
|
ACCESS_TOKEN_HEADER = "X-Shopify-Access-Token"
|
|
48
|
+
STOREFRONT_ACCESS_TOKEN_HEADER = "X-Shopify-Storefront-Access-Token"
|
|
49
|
+
STOREFRONT_BUYER_IP_HEADER = "X-Shopify-Storefront-Buyer-IP"
|
|
48
50
|
QUERY_COST_HEADER = "X-GraphQL-Cost-Include-Fields"
|
|
49
51
|
|
|
50
52
|
DEFAULT_HEADERS = { "Content-Type" => "application/json" }.freeze
|
|
@@ -64,7 +66,7 @@ module ShopifyAPI
|
|
|
64
66
|
*NetHttpTimeoutErrors.all
|
|
65
67
|
]
|
|
66
68
|
|
|
67
|
-
ENDPOINT = "https://%s/
|
|
69
|
+
ENDPOINT = "https://%s%s/api%s/graphql.json" # We omit the "/" after API for the case where there's no version
|
|
68
70
|
|
|
69
71
|
##
|
|
70
72
|
#
|
|
@@ -73,13 +75,17 @@ module ShopifyAPI
|
|
|
73
75
|
# === Arguments
|
|
74
76
|
#
|
|
75
77
|
# [shop (String)] Shopify domain to make requests against
|
|
76
|
-
# [token (String)] Shopify Admin API
|
|
78
|
+
# [token (String)] Shopify Admin API or Storefront Access Token, depending on options
|
|
77
79
|
# [options (Hash)] Client options. Optional.
|
|
78
80
|
#
|
|
79
81
|
# === Options
|
|
80
82
|
#
|
|
81
83
|
# [:retry (Boolean|Array)] If +false+ disable retries or an +Array+ of errors to retry. Can be HTTP status codes, GraphQL errors, or exception classes.
|
|
82
84
|
# [:version (String)] Shopify API version to use. Defaults to the latest version.
|
|
85
|
+
# [:storefront (Boolean)] If +true+ use the Storefront API instead of Admin API. Defaults to +false+.
|
|
86
|
+
# [:ip (String)] Optional buyer IP address for Storefront API (sets X-Shopify-Storefront-Buyer-IP header). Only used when :storefront is +true+.
|
|
87
|
+
# [:open_timeout (Numeric)] Number of seconds to wait for the connection to open. Defaults to Net::HTTP's default.
|
|
88
|
+
# [:read_timeout (Numeric)] Number of seconds to wait for a response. Defaults to Net::HTTP's default.
|
|
83
89
|
# [:max_attempts (Integer)] Maximum number of retry attempts across all errors. Defaults to +10+
|
|
84
90
|
# [:base_delay (Float)] Exponential backoff base delay. Defaults to +0.5+
|
|
85
91
|
# [:jitter (Boolean)] Exponential backoff jitter (random delay added to backoff). Defaults to +true+
|
|
@@ -98,13 +104,25 @@ module ShopifyAPI
|
|
|
98
104
|
|
|
99
105
|
@domain = shopify_domain(shop)
|
|
100
106
|
@options = options || {}
|
|
107
|
+
|
|
101
108
|
@raise_on_warnings = @options[:raise_on_warnings]
|
|
109
|
+
@storefront = !!@options[:storefront]
|
|
110
|
+
@open_timeout = @options[:open_timeout]
|
|
111
|
+
@read_timeout = @options[:read_timeout]
|
|
102
112
|
|
|
103
113
|
@headers = DEFAULT_HEADERS.dup
|
|
104
|
-
|
|
114
|
+
|
|
115
|
+
if @storefront
|
|
116
|
+
@headers[STOREFRONT_ACCESS_TOKEN_HEADER] = token
|
|
117
|
+
@headers[STOREFRONT_BUYER_IP_HEADER] = @options[:ip] if @options[:ip]
|
|
118
|
+
else
|
|
119
|
+
@headers[ACCESS_TOKEN_HEADER] = token
|
|
120
|
+
end
|
|
121
|
+
|
|
105
122
|
@headers[QUERY_COST_HEADER] = "true" unless @options[:retry] == false
|
|
106
123
|
|
|
107
|
-
|
|
124
|
+
admin_path = @storefront ? "" : "/admin"
|
|
125
|
+
@endpoint = URI(sprintf(ENDPOINT, @domain, admin_path, !@options[:version].to_s.strip.empty? ? "/#{@options[:version]}" : ""))
|
|
108
126
|
@backoff_options = DEFAULT_BACKOFF_OPTIONS.merge(@options.slice(*DEFAULT_BACKOFF_OPTIONS.keys))
|
|
109
127
|
|
|
110
128
|
if @options[:debug]
|
|
@@ -256,6 +274,8 @@ module ShopifyAPI
|
|
|
256
274
|
|
|
257
275
|
request = Net::HTTP.new(@endpoint.host, @endpoint.port)
|
|
258
276
|
request.use_ssl = true
|
|
277
|
+
request.open_timeout = @open_timeout if @open_timeout
|
|
278
|
+
request.read_timeout = @read_timeout if @read_timeout
|
|
259
279
|
request.set_debug_output(@debug) if @debug
|
|
260
280
|
|
|
261
281
|
request.start { |http| http.request(post) }
|
|
@@ -381,6 +401,8 @@ module ShopifyAPI
|
|
|
381
401
|
:after => %w[hasNextPage endCursor].freeze
|
|
382
402
|
}.freeze
|
|
383
403
|
|
|
404
|
+
attr_reader :cursor
|
|
405
|
+
|
|
384
406
|
def initialize(gql, *options)
|
|
385
407
|
@gql = gql
|
|
386
408
|
@options = normalize_options(options)
|
|
@@ -391,7 +413,8 @@ module ShopifyAPI
|
|
|
391
413
|
raise ArgumentError, "query does not contain the pagination variable '#{@options[:variable]}'"
|
|
392
414
|
end
|
|
393
415
|
|
|
394
|
-
variables
|
|
416
|
+
variables = (variables || {}).dup
|
|
417
|
+
@cursor = variables[@options[:variable]] || variables[@options[:variable].to_sym]
|
|
395
418
|
pagination_finder = @options[@options[:direction]]
|
|
396
419
|
|
|
397
420
|
enumerator = Enumerator.new do |y|
|
|
@@ -399,10 +422,10 @@ module ShopifyAPI
|
|
|
399
422
|
page = @gql.execute(q, variables)
|
|
400
423
|
y << page
|
|
401
424
|
|
|
402
|
-
cursor = pagination_finder[page]
|
|
403
|
-
break unless cursor
|
|
425
|
+
@cursor = pagination_finder[page]
|
|
426
|
+
break unless @cursor
|
|
404
427
|
|
|
405
|
-
variables[@options[:variable]] = cursor
|
|
428
|
+
variables[@options[:variable]] = @cursor
|
|
406
429
|
end
|
|
407
430
|
end
|
|
408
431
|
|
|
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
|
9
9
|
spec.authors = ["Skye Shaw"]
|
|
10
10
|
spec.email = ["skye.shaw@gmail.com"]
|
|
11
11
|
|
|
12
|
-
spec.summary = %q{Lightweight, no-nonsense, Shopify GraphQL
|
|
12
|
+
spec.summary = %q{Lightweight, no-nonsense, Shopify Admin & Storefront GraphQL API client with built-in pagination and retry}
|
|
13
13
|
spec.homepage = "https://github.com/ScreenStaring/shopify_api-graphql-tiny"
|
|
14
14
|
spec.license = "MIT"
|
|
15
15
|
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: shopify_api-graphql-tiny
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Skye Shaw
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-
|
|
10
|
+
date: 2026-11-18 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: net_http_timeout_errors
|
|
@@ -123,6 +123,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
123
123
|
requirements: []
|
|
124
124
|
rubygems_version: 3.6.2
|
|
125
125
|
specification_version: 4
|
|
126
|
-
summary: Lightweight, no-nonsense, Shopify GraphQL
|
|
127
|
-
pagination and retry
|
|
126
|
+
summary: Lightweight, no-nonsense, Shopify Admin & Storefront GraphQL API client with
|
|
127
|
+
built-in pagination and retry
|
|
128
128
|
test_files: []
|