shopify_api-graphql-tiny 1.0.2 → 1.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 18495ff517670050b05536c1ef5fda702e689a4ffab229eba78fd2aba055dce5
4
- data.tar.gz: c374cf2ae48b8ed7de70b5ec8501841593535ad21ef2d5591deb17c7dc96fdef
3
+ metadata.gz: 28d098f2ad608cf375916eb9efdf9c3278b514fc632058a835c1566989a4538b
4
+ data.tar.gz: 0a1b2d891a11116279b0169d2d093589148538f3c8abecaa35a5bd0d3bb2363a
5
5
  SHA512:
6
- metadata.gz: 3388c846e2190e5996f780bf847d28f66c9336e0a96d53a8b6eed051fe8e38ffb18f3b32cc0abb15dfb15373d9f254eb6c8afbd2fbc050b3c19aea9c690db4de
7
- data.tar.gz: e29a9dd41cd963bd96e8025ee31c5c4ec5b6b2726164655707c214fa73062f4e30e72545ea2df0c1b2ce54c90816c564776f509e4b9e3a51ef672290d35d2aec
6
+ metadata.gz: c0a66340735b1fc42126eda00b52598cbb4f1668da9e2680d99eab359e840865a6082568e53a71550f7e2edf936c7b78e1b15998391b6485d09958c7ae9cbfd2
7
+ data.tar.gz: b1ad6ca96b39d5c5a1e06c4d4a6b5e893a3236034b10426bbd9822f25e11bd9f03deddbc0125577abf3f126c5b2d78c4176f8913aa03f68f38362529e9ac0e2b
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
- SHOPIFY_TOKEN=
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/Changes CHANGED
@@ -1,3 +1,7 @@
1
+ 2026-06-25 v1.1.0
2
+ --------------------
3
+ * Add support for requests against the storefront API
4
+
1
5
  2026-06-23 v1.0.2
2
6
  --------------------
3
7
  * 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 Admin API client with built-in pagination and retry
3
+ Lightweight, no-nonsense, Shopify Admin & Storefront GraphQL API client with built-in pagination and retry
4
4
 
5
5
  [![CI](https://github.com/ScreenStaring/shopify_api-graphql-tiny/actions/workflows/ci.yml/badge.svg)](https://github.com/ScreenStaring/shopify_api-graphql-tiny/actions)
6
6
 
@@ -74,6 +74,24 @@ 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
+
77
95
  ### Automatically Retrying Failed Requests
78
96
 
79
97
  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.
@@ -311,7 +329,6 @@ bundle exec rake rate_limit SHOPIFY_DOMAIN=your-domain SHOPIFY_TOKEN=your-token
311
329
 
312
330
  - [`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
331
  - [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
332
  - [`TinyGID`](https://github.com/sshaw/tiny_gid/) - Build Global ID (gid://) URI strings from scalar values
316
333
 
317
334
  ## License
@@ -320,4 +337,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
320
337
 
321
338
  ---
322
339
 
323
- Made by [ScreenStaring](http://screenstaring.com)
340
+ Made by [ScreenStaring](https://screenstaring.com)
@@ -3,7 +3,7 @@
3
3
  module ShopifyAPI
4
4
  module GraphQL
5
5
  class Tiny
6
- VERSION = "1.0.2"
6
+ VERSION = "1.1.0"
7
7
  end
8
8
  end
9
9
  end
@@ -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/admin/api%s/graphql.json" # Note that we omit the "/" after API for the case where there's no version.
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,15 @@ module ShopifyAPI
73
75
  # === Arguments
74
76
  #
75
77
  # [shop (String)] Shopify domain to make requests against
76
- # [token (String)] Shopify Admin API GraphQL token
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+.
83
87
  # [:max_attempts (Integer)] Maximum number of retry attempts across all errors. Defaults to +10+
84
88
  # [:base_delay (Float)] Exponential backoff base delay. Defaults to +0.5+
85
89
  # [:jitter (Boolean)] Exponential backoff jitter (random delay added to backoff). Defaults to +true+
@@ -98,13 +102,23 @@ module ShopifyAPI
98
102
 
99
103
  @domain = shopify_domain(shop)
100
104
  @options = options || {}
105
+
101
106
  @raise_on_warnings = @options[:raise_on_warnings]
107
+ @storefront = !!@options[:storefront]
102
108
 
103
109
  @headers = DEFAULT_HEADERS.dup
104
- @headers[ACCESS_TOKEN_HEADER] = token
110
+
111
+ if @storefront
112
+ @headers[STOREFRONT_ACCESS_TOKEN_HEADER] = token
113
+ @headers[STOREFRONT_BUYER_IP_HEADER] = @options[:ip] if @options[:ip]
114
+ else
115
+ @headers[ACCESS_TOKEN_HEADER] = token
116
+ end
117
+
105
118
  @headers[QUERY_COST_HEADER] = "true" unless @options[:retry] == false
106
119
 
107
- @endpoint = URI(sprintf(ENDPOINT, @domain, !@options[:version].to_s.strip.empty? ? "/#{@options[:version]}" : ""))
120
+ admin_path = @storefront ? "" : "/admin"
121
+ @endpoint = URI(sprintf(ENDPOINT, @domain, admin_path, !@options[:version].to_s.strip.empty? ? "/#{@options[:version]}" : ""))
108
122
  @backoff_options = DEFAULT_BACKOFF_OPTIONS.merge(@options.slice(*DEFAULT_BACKOFF_OPTIONS.keys))
109
123
 
110
124
  if @options[:debug]
@@ -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 Admin API client with built-in pagination and retry}
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.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Skye Shaw
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2026-06-23 00:00:00.000000000 Z
10
+ date: 2026-06-25 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 Admin API client with built-in
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: []