shopify_graphql 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fe9ea3cbb7c46d86fe1281d9658cc1de370db1b306b29aa331c1c8ac9ae94f0d
4
- data.tar.gz: ab91936f744cd3c40ee1b81952426a839e26fb3fd8b9ca55defa5248c22ed812
3
+ metadata.gz: db26915271fd8d34d5efe679772d946dda1e897ef2e608708cd6c6a07f646a38
4
+ data.tar.gz: 0ab8496a613921d8e8dc2ff4fd727ac46140fac042ae9c3d54ddbaec29cd3592
5
5
  SHA512:
6
- metadata.gz: 2ef56f4a0248e446d3063fd6ef92e13743d65a6ecefd523c8b70444f52353667e9b082efb13177a5912ad598425c6382e0ac36321aab231b46f73871e1109a06
7
- data.tar.gz: 3c483532a0d6dc2d853a172a357a07319466bad2313937a1f57f4f359a2978affeacb80f3e3b5c3df287bc2e07565d692e831dff7564a22cc9a02a1522bab59f
6
+ metadata.gz: dd0087c86d4efa3bbec51001f98373e5d9c506e7740991c1614c207af0ac93c59b86161916a303f79be074edb1341bc2b38bd2b95290f12af24bd247343024d6
7
+ data.tar.gz: d3f98b28aac804244d13be7610f9e69e19b28633335002fd20a5bff6c99a67b99aa7efe93da4ad3f2174e8445985273706a2a0c6d7392e072e8241a2b8b8e897
data/README.md CHANGED
@@ -86,6 +86,68 @@ puts product.title
86
86
  ```
87
87
  </details>
88
88
 
89
+ ### Query with custom headers
90
+
91
+ <details><summary>Click to expand</summary>
92
+ You can pass custom headers to any GraphQL query or mutation by using the `headers` parameter. A common use case is setting the `Accept-Language` header to retrieve content in specific languages:
93
+
94
+ ```rb
95
+ # Pass custom headers to a direct GraphQL call to get French content
96
+ response = ShopifyGraphql.execute(QUERY, headers: { "Accept-Language" => "fr" })
97
+
98
+ # Or create a language-aware query wrapper
99
+ class GetProduct
100
+ include ShopifyGraphql::Query
101
+
102
+ QUERY = <<~GRAPHQL
103
+ query($id: ID!) {
104
+ product(id: $id) {
105
+ id
106
+ title
107
+ description
108
+ seo {
109
+ title
110
+ description
111
+ }
112
+ }
113
+ }
114
+ GRAPHQL
115
+
116
+ def call(id:, language: nil)
117
+ headers = language ? { "Accept-Language" => language } : nil
118
+ response = execute(QUERY, headers: headers, id: id)
119
+ response.data = response.data.product
120
+ response
121
+ end
122
+ end
123
+
124
+ # Then use it to get content in different languages
125
+ french_product = GetProduct.call(
126
+ id: "gid://shopify/Product/12345",
127
+ language: "fr"
128
+ ).data
129
+
130
+ puts french_product.title # => "Le Produit"
131
+ puts french_product.description # => "Description en français"
132
+
133
+ # Get content in Japanese
134
+ japanese_product = GetProduct.call(
135
+ id: "gid://shopify/Product/12345",
136
+ language: "ja"
137
+ ).data
138
+
139
+ puts japanese_product.title # => "商品名"
140
+ puts japanese_product.description # => "商品の説明"
141
+ ```
142
+
143
+ The `Accept-Language` header tells Shopify which language to return the content in. This is particularly useful for:
144
+ - Retrieving translated content for products, collections, and pages
145
+ - Building multi-language storefronts
146
+ - Showing localized SEO content
147
+
148
+ You can also use custom headers for other purposes like passing metadata or context with your GraphQL requests.
149
+ </details>
150
+
89
151
  ### Query with data parsing
90
152
 
91
153
  <details><summary>Click to expand</summary>
@@ -48,6 +48,10 @@ module ShopifyGraphql
48
48
  transactionalSmsDisabled
49
49
  enabledPresentmentCurrencies
50
50
  #SMS_CONSENT#
51
+ resourceLimits {
52
+ maxProductOptions
53
+ maxProductVariants
54
+ }
51
55
  }
52
56
  #LOCALES_SUBQUERY#
53
57
  }
@@ -127,7 +131,9 @@ module ShopifyGraphql
127
131
  checkout_api_supported: data.shop.checkoutApiSupported,
128
132
  transactional_sms_disabled: data.shop.transactionalSmsDisabled,
129
133
  enabled_presentment_currencies: data.shop.enabledPresentmentCurrencies,
130
- marketing_sms_consent_enabled_at_checkout: data.shop.marketingSmsConsentEnabledAtCheckout
134
+ marketing_sms_consent_enabled_at_checkout: data.shop.marketingSmsConsentEnabledAtCheckout,
135
+ max_product_options: data.shop.resourceLimits.maxProductOptions,
136
+ max_product_variants: data.shop.resourceLimits.maxProductVariants
131
137
  )
132
138
  if with_locales
133
139
  response.primary_locale = data.shopLocales.find(&:primary).locale
@@ -29,8 +29,8 @@ module ShopifyGraphql
29
29
  @client ||= ShopifyAPI::Clients::Graphql::Admin.new(session: ShopifyAPI::Context.active_session)
30
30
  end
31
31
 
32
- def execute(query, **variables)
33
- response = client.query(query: query, variables: variables)
32
+ def execute(query, headers: nil, **variables)
33
+ response = client.query(query: query, variables: variables, headers: headers)
34
34
  Response.new(handle_response(response))
35
35
  rescue ShopifyAPI::Errors::HttpResponseError => e
36
36
  Response.new(handle_response(e.response, e))
@@ -1,3 +1,3 @@
1
1
  module ShopifyGraphql
2
- VERSION = "2.0.0"
2
+ VERSION = "2.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shopify_graphql
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kirill Platonov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-22 00:00:00.000000000 Z
11
+ date: 2025-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails