shopify_api 4.9.0 → 9.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (281) hide show
  1. checksums.yaml +5 -5
  2. data/.github/CODEOWNERS +1 -0
  3. data/.github/ISSUE_TEMPLATE.md +36 -0
  4. data/.github/probots.yml +2 -0
  5. data/.github/workflows/build.yml +41 -0
  6. data/.gitignore +5 -1
  7. data/.rubocop.yml +28 -0
  8. data/.rubocop_todo.yml +75 -0
  9. data/CHANGELOG.md +491 -0
  10. data/CONTRIBUTING.md +1 -1
  11. data/Gemfile +6 -2
  12. data/Gemfile.lock +151 -0
  13. data/Gemfile_ar41 +5 -0
  14. data/Gemfile_ar50 +5 -0
  15. data/Gemfile_ar51 +5 -0
  16. data/Gemfile_ar_master +0 -1
  17. data/README.md +492 -100
  18. data/RELEASING +10 -9
  19. data/Rakefile +21 -5
  20. data/SECURITY.md +59 -0
  21. data/docker-compose.yml +13 -0
  22. data/docs/_config.yml +1 -0
  23. data/docs/_includes/footer.html +28 -0
  24. data/docs/_includes/head.html +28 -0
  25. data/docs/_layouts/index.html +57 -0
  26. data/docs/graphql.md +241 -0
  27. data/docs/index.md +639 -0
  28. data/lib/active_resource/connection_ext.rb +1 -0
  29. data/lib/active_resource/detailed_log_subscriber.rb +43 -7
  30. data/lib/active_resource/json_errors.rb +8 -2
  31. data/lib/shopify_api.rb +16 -6
  32. data/lib/shopify_api/api_access.rb +57 -0
  33. data/lib/shopify_api/api_version.rb +206 -0
  34. data/lib/shopify_api/connection.rb +7 -4
  35. data/lib/shopify_api/countable.rb +3 -2
  36. data/lib/shopify_api/disable_prefix_check.rb +31 -0
  37. data/lib/shopify_api/events.rb +2 -1
  38. data/lib/shopify_api/graphql.rb +103 -0
  39. data/lib/shopify_api/graphql/http_client.rb +22 -0
  40. data/lib/shopify_api/graphql/railtie.rb +17 -0
  41. data/lib/shopify_api/graphql/task.rake +100 -0
  42. data/lib/shopify_api/limits.rb +9 -9
  43. data/lib/shopify_api/message_enricher.rb +25 -0
  44. data/lib/shopify_api/meta.rb +14 -0
  45. data/lib/shopify_api/metafields.rb +5 -4
  46. data/lib/shopify_api/paginated_collection.rb +69 -0
  47. data/lib/shopify_api/pagination_link_headers.rb +34 -0
  48. data/lib/shopify_api/resources.rb +3 -1
  49. data/lib/shopify_api/resources/abandoned_checkout.rb +7 -0
  50. data/lib/shopify_api/resources/access_scope.rb +10 -0
  51. data/lib/shopify_api/resources/access_token.rb +1 -0
  52. data/lib/shopify_api/resources/address.rb +1 -0
  53. data/lib/shopify_api/resources/announcement.rb +2 -1
  54. data/lib/shopify_api/resources/api_permission.rb +9 -0
  55. data/lib/shopify_api/resources/application_charge.rb +1 -0
  56. data/lib/shopify_api/resources/application_credit.rb +1 -0
  57. data/lib/shopify_api/resources/array_base.rb +13 -0
  58. data/lib/shopify_api/resources/article.rb +3 -2
  59. data/lib/shopify_api/resources/asset.rb +28 -23
  60. data/lib/shopify_api/resources/assigned_fulfillment_order.rb +16 -0
  61. data/lib/shopify_api/resources/base.rb +101 -24
  62. data/lib/shopify_api/resources/billing_address.rb +2 -1
  63. data/lib/shopify_api/resources/blog.rb +2 -1
  64. data/lib/shopify_api/resources/carrier_service.rb +1 -0
  65. data/lib/shopify_api/resources/cart.rb +2 -1
  66. data/lib/shopify_api/resources/checkout.rb +27 -1
  67. data/lib/shopify_api/resources/collect.rb +2 -0
  68. data/lib/shopify_api/resources/collection.rb +14 -0
  69. data/lib/shopify_api/resources/collection_listing.rb +11 -1
  70. data/lib/shopify_api/resources/collection_publication.rb +10 -0
  71. data/lib/shopify_api/resources/comment.rb +20 -5
  72. data/lib/shopify_api/resources/country.rb +1 -0
  73. data/lib/shopify_api/resources/currency.rb +6 -0
  74. data/lib/shopify_api/resources/custom_collection.rb +7 -6
  75. data/lib/shopify_api/resources/customer.rb +2 -1
  76. data/lib/shopify_api/resources/customer_group.rb +1 -0
  77. data/lib/shopify_api/resources/{customer_invite_message.rb → customer_invite.rb} +1 -0
  78. data/lib/shopify_api/resources/customer_saved_search.rb +4 -1
  79. data/lib/shopify_api/resources/discount_code.rb +1 -0
  80. data/lib/shopify_api/resources/discount_code_batch.rb +34 -0
  81. data/lib/shopify_api/resources/draft_order.rb +1 -0
  82. data/lib/shopify_api/resources/draft_order_invoice.rb +1 -0
  83. data/lib/shopify_api/resources/event.rb +2 -0
  84. data/lib/shopify_api/resources/fulfillment.rb +46 -3
  85. data/lib/shopify_api/resources/fulfillment_event.rb +2 -1
  86. data/lib/shopify_api/resources/fulfillment_order.rb +151 -0
  87. data/lib/shopify_api/resources/fulfillment_order_locations_for_move.rb +5 -0
  88. data/lib/shopify_api/resources/fulfillment_request.rb +1 -0
  89. data/lib/shopify_api/resources/fulfillment_service.rb +1 -0
  90. data/lib/shopify_api/resources/fulfillment_v2.rb +21 -0
  91. data/lib/shopify_api/resources/gift_card.rb +1 -0
  92. data/lib/shopify_api/resources/image.rb +4 -3
  93. data/lib/shopify_api/resources/inventory_item.rb +6 -0
  94. data/lib/shopify_api/resources/inventory_level.rb +54 -0
  95. data/lib/shopify_api/resources/line_item.rb +10 -1
  96. data/lib/shopify_api/resources/location.rb +4 -0
  97. data/lib/shopify_api/resources/marketing_event.rb +3 -0
  98. data/lib/shopify_api/resources/metafield.rb +2 -0
  99. data/lib/shopify_api/resources/note_attribute.rb +1 -0
  100. data/lib/shopify_api/resources/option.rb +1 -0
  101. data/lib/shopify_api/resources/order.rb +25 -5
  102. data/lib/shopify_api/resources/order_risk.rb +1 -0
  103. data/lib/shopify_api/resources/page.rb +1 -0
  104. data/lib/shopify_api/resources/payment.rb +7 -0
  105. data/lib/shopify_api/resources/payment_details.rb +1 -0
  106. data/lib/shopify_api/resources/ping.rb +3 -0
  107. data/lib/shopify_api/resources/policy.rb +1 -0
  108. data/lib/shopify_api/resources/price_rule.rb +1 -1
  109. data/lib/shopify_api/resources/product.rb +33 -7
  110. data/lib/shopify_api/resources/product_listing.rb +9 -1
  111. data/lib/shopify_api/resources/product_publication.rb +10 -0
  112. data/lib/shopify_api/resources/province.rb +1 -0
  113. data/lib/shopify_api/resources/publication.rb +5 -0
  114. data/lib/shopify_api/resources/receipt.rb +1 -0
  115. data/lib/shopify_api/resources/recurring_application_charge.rb +4 -1
  116. data/lib/shopify_api/resources/redirect.rb +1 -0
  117. data/lib/shopify_api/resources/refund.rb +6 -4
  118. data/lib/shopify_api/resources/report.rb +1 -0
  119. data/lib/shopify_api/resources/resource_feedback.rb +1 -1
  120. data/lib/shopify_api/resources/rule.rb +1 -0
  121. data/lib/shopify_api/resources/script_tag.rb +1 -0
  122. data/lib/shopify_api/resources/shipping_address.rb +1 -0
  123. data/lib/shopify_api/resources/shipping_line.rb +2 -1
  124. data/lib/shopify_api/resources/shipping_rate.rb +7 -0
  125. data/lib/shopify_api/resources/shipping_zone.rb +1 -0
  126. data/lib/shopify_api/resources/shop.rb +10 -7
  127. data/lib/shopify_api/resources/smart_collection.rb +3 -3
  128. data/lib/shopify_api/resources/storefront_access_token.rb +1 -0
  129. data/lib/shopify_api/resources/tax_line.rb +1 -0
  130. data/lib/shopify_api/resources/tax_service.rb +1 -0
  131. data/lib/shopify_api/resources/tender_transaction.rb +6 -0
  132. data/lib/shopify_api/resources/theme.rb +1 -0
  133. data/lib/shopify_api/resources/transaction.rb +1 -0
  134. data/lib/shopify_api/resources/usage_charge.rb +1 -0
  135. data/lib/shopify_api/resources/user.rb +1 -0
  136. data/lib/shopify_api/resources/variant.rb +35 -0
  137. data/lib/shopify_api/resources/webhook.rb +1 -0
  138. data/lib/shopify_api/session.rb +109 -45
  139. data/lib/shopify_api/version.rb +2 -1
  140. data/lib/verify_docs.rb +8 -0
  141. data/service.yml +8 -0
  142. data/shopify_api.gemspec +19 -8
  143. data/test/abandoned_checkouts_test.rb +29 -0
  144. data/test/access_scope_test.rb +23 -0
  145. data/test/access_token_test.rb +6 -5
  146. data/test/active_resource/json_errors_test.rb +6 -6
  147. data/test/api_access_test.rb +153 -0
  148. data/test/api_permission_test.rb +9 -0
  149. data/test/api_version_test.rb +157 -0
  150. data/test/application_charge_test.rb +30 -27
  151. data/test/application_credit_test.rb +10 -9
  152. data/test/article_test.rb +34 -35
  153. data/test/asset_test.rb +14 -6
  154. data/test/assigned_fulfillment_order_test.rb +78 -0
  155. data/test/base_test.rb +147 -59
  156. data/test/blog_test.rb +4 -3
  157. data/test/carrier_service_test.rb +7 -6
  158. data/test/cart_test.rb +2 -1
  159. data/test/checkouts_test.rb +72 -4
  160. data/test/collect_test.rb +4 -3
  161. data/test/collection_listing_test.rb +56 -13
  162. data/test/collection_publication_test.rb +40 -0
  163. data/test/collection_test.rb +50 -0
  164. data/test/countable_test.rb +3 -2
  165. data/test/currency_test.rb +21 -0
  166. data/test/custom_collection_test.rb +4 -3
  167. data/test/customer_saved_search_test.rb +18 -8
  168. data/test/customer_test.rb +22 -14
  169. data/test/detailed_log_subscriber_test.rb +113 -19
  170. data/test/discount_code_batch_test.rb +41 -0
  171. data/test/discount_code_test.rb +22 -16
  172. data/test/draft_order_test.rb +68 -52
  173. data/test/fixtures/abandoned_checkout.json +184 -0
  174. data/test/fixtures/abandoned_checkouts.json +186 -0
  175. data/test/fixtures/access_scopes.json +10 -0
  176. data/test/fixtures/api_versions.json +38 -0
  177. data/test/fixtures/apis.json +42 -0
  178. data/test/fixtures/assigned_fulfillment_orders.json +80 -0
  179. data/test/fixtures/checkout.json +160 -0
  180. data/test/fixtures/checkouts.json +25 -49
  181. data/test/fixtures/collection.json +17 -0
  182. data/test/fixtures/collection_listing_product_ids2.json +1 -0
  183. data/test/fixtures/collection_products.json +47 -0
  184. data/test/fixtures/collection_publication.json +11 -0
  185. data/test/fixtures/collection_publications.json +13 -0
  186. data/test/fixtures/currencies.json +25 -0
  187. data/test/fixtures/discount_code_batch.json +14 -0
  188. data/test/fixtures/discount_code_batch_discount_codes.json +21 -0
  189. data/test/fixtures/fulfillment_order.json +39 -0
  190. data/test/fixtures/fulfillment_order_locations_for_move.json +18 -0
  191. data/test/fixtures/fulfillment_orders.json +80 -0
  192. data/test/fixtures/fulfillments.json +53 -0
  193. data/test/fixtures/graphql/2019-10.json +1083 -0
  194. data/test/fixtures/graphql/dummy_schema.rb +16 -0
  195. data/test/fixtures/graphql/unstable.json +1083 -0
  196. data/test/fixtures/inventory_level.json +7 -0
  197. data/test/fixtures/inventory_levels.json +24 -0
  198. data/test/fixtures/order_with_properties.json +373 -0
  199. data/test/fixtures/payment.json +7 -0
  200. data/test/fixtures/payments.json +9 -0
  201. data/test/fixtures/ping/conversation.json +1 -0
  202. data/test/fixtures/ping/failed_delivery_confirmation.json +1 -0
  203. data/test/fixtures/ping/message.json +1 -0
  204. data/test/fixtures/ping/successful_delivery_confirmation.json +1 -0
  205. data/test/fixtures/product_listing_product_ids.json +1 -1
  206. data/test/fixtures/product_listing_product_ids2.json +1 -0
  207. data/test/fixtures/product_publication.json +11 -0
  208. data/test/fixtures/product_publications.json +13 -0
  209. data/test/fixtures/publications.json +9 -0
  210. data/test/fixtures/shipping_rates.json +12 -0
  211. data/test/fixtures/smart_collection_products.json +155 -0
  212. data/test/fixtures/tender_transactions.json +52 -0
  213. data/test/fulfillment_event_test.rb +31 -26
  214. data/test/fulfillment_order_test.rb +530 -0
  215. data/test/fulfillment_order_test_helper.rb +8 -0
  216. data/test/fulfillment_request_test.rb +10 -8
  217. data/test/fulfillment_service_test.rb +13 -12
  218. data/test/fulfillment_test.rb +198 -20
  219. data/test/fulfillment_v2_test.rb +66 -0
  220. data/test/gift_card_test.rb +6 -4
  221. data/test/graphql/http_client_test.rb +26 -0
  222. data/test/graphql_test.rb +190 -0
  223. data/test/image_test.rb +19 -17
  224. data/test/inventory_level_test.rb +68 -0
  225. data/test/lib/webmock_extensions/last_request.rb +16 -0
  226. data/test/limits_test.rb +4 -3
  227. data/test/location_test.rb +15 -0
  228. data/test/marketing_event_test.rb +21 -21
  229. data/test/message_enricher_test.rb +45 -0
  230. data/test/meta_test.rb +47 -0
  231. data/test/metafield_test.rb +30 -20
  232. data/test/order_risk_test.rb +17 -16
  233. data/test/order_test.rb +110 -17
  234. data/test/pagination_test.rb +290 -0
  235. data/test/payment_test.rb +19 -0
  236. data/test/policy_test.rb +6 -5
  237. data/test/price_rule_test.rb +20 -15
  238. data/test/product_listing_test.rb +72 -15
  239. data/test/product_publication_test.rb +40 -0
  240. data/test/product_test.rb +80 -19
  241. data/test/publication_test.rb +12 -0
  242. data/test/recurring_application_charge_test.rb +105 -50
  243. data/test/redirect_test.rb +4 -3
  244. data/test/refund_test.rb +22 -17
  245. data/test/report_test.rb +12 -10
  246. data/test/resource_feedback_test.rb +14 -13
  247. data/test/script_tag_test.rb +10 -9
  248. data/test/session_test.rb +497 -111
  249. data/test/shipping_rate_test.rb +17 -0
  250. data/test/shipping_zone_test.rb +4 -3
  251. data/test/shop_test.rb +47 -33
  252. data/test/smart_collection_test.rb +5 -4
  253. data/test/storefront_access_token_test.rb +13 -15
  254. data/test/tax_service_test.rb +7 -3
  255. data/test/tender_transaction_test.rb +18 -0
  256. data/test/test_helper.rb +98 -67
  257. data/test/transaction_test.rb +4 -3
  258. data/test/usage_charge_test.rb +12 -8
  259. data/test/user_test.rb +4 -3
  260. data/test/variant_test.rb +50 -20
  261. data/test/webhook_test.rb +10 -7
  262. metadata +196 -37
  263. data/.travis.yml +0 -36
  264. data/CHANGELOG +0 -292
  265. data/Gemfile_ar30 +0 -6
  266. data/Gemfile_ar31 +0 -6
  267. data/Gemfile_ar32 +0 -6
  268. data/Gemfile_ar40 +0 -6
  269. data/bin/shopify +0 -3
  270. data/lib/active_resource/base_ext.rb +0 -21
  271. data/lib/active_resource/disable_prefix_check.rb +0 -36
  272. data/lib/active_resource/to_query.rb +0 -10
  273. data/lib/shopify_api/json_format.rb +0 -18
  274. data/lib/shopify_api/resources/discount.rb +0 -11
  275. data/lib/shopify_api/resources/o_auth.rb +0 -9
  276. data/test/discount_test.rb +0 -52
  277. data/test/fixtures/discount.json +0 -17
  278. data/test/fixtures/discount_disabled.json +0 -17
  279. data/test/fixtures/discounts.json +0 -34
  280. data/test/fixtures/o_auth_revoke.json +0 -5
  281. data/test/o_auth_test.rb +0 -8
data/RELEASING CHANGED
@@ -2,15 +2,16 @@ Releasing ShopifyAPI
2
2
 
3
3
  1. Check the Semantic Versioning page for info on how to version the new release: http://semver.org
4
4
  2. Update the version of ShopifyAPI in lib/shopify_api/version.rb
5
- 3. Add a CHANGELOG entry for the new release with the date
6
- 4. Commit the changes with a commit message like "Packaging for release X.Y.Z"
7
- 5. Tag the release with the version (Leave REV blank for HEAD or provide a SHA)
5
+ 3. Run `bundle`
6
+ 4. Add a CHANGELOG entry for the new release
7
+ 5. Commit the changes with a commit message like "Packaging for release X.Y.Z"
8
+ 6. Tag the release with the version (Leave REV blank for HEAD or provide a SHA)
8
9
  $ git tag vX.Y.Z REV
9
- 6. Push out the changes
10
+ 7. Push out the changes
10
11
  $ git push
11
- 7. Push out the tags
12
+ 8. Push out the tags
12
13
  $ git push --tags
13
- 8. Build the new .gem from the updated .gemspec
14
- $ gem build shopify_api.gemspec
15
- 9. Publish the Gem to gemcutter
16
- $ gem push shopify_api-X.Y.Z.gem
14
+ 9. Publish the gem using Shipit
15
+ 10. Consider if the dependency in Shopify/shopify needs updated. It's used only by the tests so is a low risk change.
16
+ Also consider Shopify/shopify_app whose gemspec depends on this.
17
+ We don't need to do this for every release, but we should try to keep them relatively up to date.
data/Rakefile CHANGED
@@ -1,13 +1,17 @@
1
+ # frozen_string_literal: true
1
2
  require 'rake'
2
3
  require "bundler/gem_tasks"
3
-
4
4
  require 'rake/testtask'
5
+ require 'rubocop/rake_task'
6
+
5
7
  Rake::TestTask.new(:test) do |test|
6
8
  test.libs << 'lib' << 'test'
7
9
  test.pattern = 'test/**/*_test.rb'
8
- test.verbose = true
10
+ test.warning = false
9
11
  end
10
12
 
13
+ RuboCop::RakeTask.new
14
+
11
15
  begin
12
16
  require 'rcov/rcovtask'
13
17
  Rcov::RcovTask.new do |test|
@@ -16,12 +20,19 @@ begin
16
20
  test.verbose = true
17
21
  end
18
22
  rescue LoadError
19
- task :rcov do
20
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
23
+ task(:rcov) do
24
+ abort("RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov")
21
25
  end
22
26
  end
23
27
 
24
- task :default => :test
28
+ task(default: [:test, :rubocop, :verify_docs])
29
+
30
+ require 'verify_docs'
31
+ task(:verify_docs) do
32
+ unless VerifyDocs.call
33
+ abort("\nWARNING: docs/index.md and README.md no longer have identical content. Please correct this.")
34
+ end
35
+ end
25
36
 
26
37
  require 'rdoc/task'
27
38
  Rake::RDocTask.new do |rdoc|
@@ -37,3 +48,8 @@ Rake::RDocTask.new do |rdoc|
37
48
  rdoc.rdoc_files.include('README*')
38
49
  rdoc.rdoc_files.include('lib/**/*.rb')
39
50
  end
51
+
52
+ task(:docker) do
53
+ cmd = "docker-compose up -d && docker exec -i -t shopify_api bash"
54
+ exec(cmd, err: File::NULL)
55
+ end
data/SECURITY.md ADDED
@@ -0,0 +1,59 @@
1
+ # Security Policy
2
+
3
+ ## Supported versions
4
+
5
+ ### New features
6
+
7
+ New features will only be added to the master branch and will not be made available in point releases.
8
+
9
+ ### Bug fixes
10
+
11
+ Only the latest release series will receive bug fixes. When enough bugs are fixed and its deemed worthy to release a new gem, this is the branch it happens from.
12
+
13
+ ### Security issues
14
+
15
+ Only the latest release series will receive patches and new versions in case of a security issue.
16
+
17
+ ### Severe security issues
18
+
19
+ For severe security issues we will provide new versions as above, and also the last major release series will receive patches and new versions. The classification of the security issue is judged by the core team.
20
+
21
+ ### Unsupported Release Series
22
+
23
+ When a release series is no longer supported, it's your own responsibility to deal with bugs and security issues. If you are not comfortable maintaining your own versions, you should upgrade to a supported version.
24
+
25
+ ## Reporting a bug
26
+
27
+ All security bugs in shopify repositories should be reported to [our hackerone program](https://hackerone.com/shopify)
28
+ Shopify's whitehat program is our way to reward security researchers for finding serious security vulnerabilities in the In Scope properties listed at the bottom of this page, including our core application (all functionality associated with a Shopify store, particularly your-store.myshopify.com/admin) and certain ancillary applications.
29
+
30
+ ## Disclosure Policy
31
+
32
+ We look forward to working with all security researchers and strive to be respectful, always assume the best and treat others as peers. We expect the same in return from all participants. To achieve this, our team strives to:
33
+
34
+ - Reply to all reports within one business day and triage within two business days (if applicable)
35
+ - Be as transparent as possible, answering all inquires about our report decisions and adding hackers to duplicate HackerOne reports
36
+ - Award bounties within a week of resolution (excluding extenuating circumstances)
37
+ - Only close reports as N/A when the issue reported is included in Known Issues, Ineligible Vulnerabilities Types or lacks evidence of a vulnerability
38
+
39
+ **The following rules must be followed in order for any rewards to be paid:**
40
+
41
+ - You may only test against shops you have created which include your HackerOne YOURHANDLE @ wearehackerone.com registered email address.
42
+ - You must not attempt to gain access to, or interact with, any shops other than those created by you.
43
+ - The use of commercial scanners is prohibited (e.g., Nessus).
44
+ - Rules for reporting must be followed.
45
+ - Do not disclose any issues publicly before they have been resolved.
46
+ - Shopify reserves the right to modify the rules for this program or deem any submissions invalid at any time. Shopify may cancel the whitehat program without notice at any time.
47
+ - Contacting Shopify Support over chat, email or phone about your HackerOne report is not allowed. We may disqualify you from receiving a reward, or from participating in the program altogether.
48
+ - You are not an employee of Shopify; employees should report bugs to the internal bug bounty program.
49
+ - You hereby represent, warrant and covenant that any content you submit to Shopify is an original work of authorship and that you are legally entitled to grant the rights and privileges conveyed by these terms. You further represent, warrant and covenant that the consent of no other person or entity is or will be necessary for Shopify to use the submitted content.
50
+ - By submitting content to Shopify, you irrevocably waive all moral rights which you may have in the content.
51
+ - All content submitted by you to Shopify under this program is licensed under the MIT License.
52
+ - You must report any discovered vulnerability to Shopify as soon as you have validated the vulnerability.
53
+ - Failure to follow any of the foregoing rules will disqualify you from participating in this program.
54
+
55
+ ** Please see our [Hackerone Profile](https://hackerone.com/shopify) for full details
56
+
57
+ ## Receiving Security Updates
58
+
59
+ To recieve all general updates to vulnerabilities, please subscribe to our hackerone [Hacktivity](https://hackerone.com/shopify/hacktivity)
@@ -0,0 +1,13 @@
1
+ version: '3.5'
2
+ services:
3
+ api:
4
+ container_name: shopify_api
5
+ image: ruby:2.6
6
+ working_dir: /shopify_api
7
+ volumes:
8
+ - .:/shopify_api
9
+ - bundle:/usr/local/bundle
10
+ command: bash -c "bundle install && tail -f /dev/null"
11
+
12
+ volumes:
13
+ bundle:
data/docs/_config.yml ADDED
@@ -0,0 +1 @@
1
+ markdown: kramdown
@@ -0,0 +1,28 @@
1
+ <meta charset="utf-8">
2
+ <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
3
+
4
+ <title>Shopify Open Source > {{ site.github.project_title }}</title>
5
+
6
+ {% if page.description %}
7
+ <meta name="description" content="{{ site.github.project_tagline }}">
8
+ {% endif %}
9
+
10
+ <link rel="canonical" href="http://shopify.github.io">
11
+
12
+ <meta name="robots" content="index, follow">
13
+ <meta name="st:robots" content="index, follow">
14
+
15
+ <meta name="viewport" content="width=device-width, initial-scale=1">
16
+
17
+ <meta property='st:title' content="Shopify Open Source > {{ site.github.project_title }}">
18
+
19
+ <link rel="shortcut icon" href="//cdn.shopify.com/assets/favicon.ico" type="image/x-icon">
20
+
21
+ <link href="//shopify.github.io/css/sub.css" rel="stylesheet" type="text/css">
22
+ <!--[if lt IE 9]>
23
+ <link href="http://shopify.github.io/css/subie.css" rel="stylesheet" type="text/css">
24
+ <![endif]-->
25
+
26
+ <!--[if IE]>
27
+ <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
28
+ <![endif]-->
@@ -0,0 +1,28 @@
1
+ <meta charset="utf-8">
2
+ <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
3
+
4
+ <title>Shopify Open Source > {{ site.github.project_title }}</title>
5
+
6
+ {% if page.description %}
7
+ <meta name="description" content="{{ site.github.project_tagline }}">
8
+ {% endif %}
9
+
10
+ <link rel="canonical" href="http://shopify.github.io">
11
+
12
+ <meta name="robots" content="index, follow">
13
+ <meta name="st:robots" content="index, follow">
14
+
15
+ <meta name="viewport" content="width=device-width, initial-scale=1">
16
+
17
+ <meta property='st:title' content="Shopify Open Source > {{ site.github.project_title }}">
18
+
19
+ <link rel="shortcut icon" href="//cdn.shopify.com/assets/favicon.ico" type="image/x-icon">
20
+
21
+ <link href="//shopify.github.io/css/sub.css" rel="stylesheet" type="text/css">
22
+ <!--[if lt IE 9]>
23
+ <link href="http://shopify.github.io/css/subie.css" rel="stylesheet" type="text/css">
24
+ <![endif]-->
25
+
26
+ <!--[if IE]>
27
+ <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
28
+ <![endif]-->
@@ -0,0 +1,57 @@
1
+ <!doctype html>
2
+ <!--[if IE 8]><html class="no-js lt-ie9" lang="en"> <![endif]-->
3
+ <!--[if IE 9 ]><html class="ie9 no-js"> <![endif]-->
4
+ <!--[if (gt IE 9)|!(IE)]><!--> <html class="no-js"> <!--<![endif]-->
5
+ <head>
6
+ {% include head.html %}
7
+ </head>
8
+ <body>
9
+ <div class="hero">
10
+ <div class="hero-lines"></div>
11
+ <header class="hero-header">
12
+ <div class="pagewidth">
13
+ <div class="logo--ie">
14
+ <img src="http://shopify.github.io/images/shopify-open-source-sub.svg" alt="Shopify Open Source" class="logo">
15
+ <span class="breadcrumb"><a href="http://shopify.github.io">Open Source</a> > {{ site.github.project_title }}</span>
16
+ </div>
17
+ <div class="repo-lang {{ site.github.language | downcase }}">
18
+ {{ site.github.language }}
19
+ </div>
20
+ </div>
21
+ </header>
22
+ <div class="pagewidth">
23
+ <div class="hero-inner">
24
+ <h1 class="hero-logo">{{ site.github.project_title }}</h1>
25
+ <h2 class="hero-text">{{ site.github.project_tagline }}</h2>
26
+ <div class="cta-buttons">
27
+ <a href="{{ site.github.zip_url }}" class="float">Download ZIP</a>
28
+ <a href="{{ site.github.repository_url }}" class="float github">
29
+ Github Repo
30
+ <i class="icon-star" title="Stars"></i> <span id="starCount"></span>
31
+ <i class="icon-forks" title="Forks"></i> <span id="forkCount"></span>
32
+ </a>
33
+ </div>
34
+ </div>
35
+ </div>
36
+ </div>
37
+
38
+ <div class="documentation">
39
+ <div class="pagewidth">
40
+
41
+ {{ content }}
42
+
43
+ </div>
44
+ </div>
45
+ {% include footer.html %}
46
+
47
+ <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
48
+ <script src="//shopify.github.io/javascripts/sub.js"></script>
49
+ <script>
50
+ jQuery(function($) {
51
+ shopifyOpenSource.init({
52
+ repo_name: '{{ site.github.repository_nwo }}'
53
+ });
54
+ });
55
+ </script>
56
+ </body>
57
+ </html>
data/docs/graphql.md ADDED
@@ -0,0 +1,241 @@
1
+ # GraphQL client
2
+
3
+ The `shopify_api` gem includes a full featured GraphQL client to interact with
4
+ Shopify's [GraphQL Admin API](https://help.shopify.com/en/api/graphql-admin-api).
5
+ GitHub's [graphql-client](https://github.com/github/graphql-client) is used as
6
+ the underlying client and this library integrates it with our existing
7
+ session, authentication, and API versioning features.
8
+
9
+ ## Example
10
+
11
+ ```ruby
12
+ client = ShopifyAPI::GraphQL.client
13
+
14
+ SHOP_NAME_QUERY = client.parse <<-'GRAPHQL'
15
+ {
16
+ shop {
17
+ name
18
+ }
19
+ }
20
+ GRAPHQL
21
+
22
+ result = client.query(SHOP_NAME_QUERY)
23
+ result.data.shop.name
24
+ ```
25
+
26
+ * [Getting started](#getting-started)
27
+ * [Rails integration](#rails-integration)
28
+ * [API versioning](#api-versioning)
29
+ * [Initialization process](#initialization-process)
30
+ * [Migration guide](#migration-guide)
31
+
32
+ ## Getting started
33
+
34
+ 1. [Dump the schema](#dump-the-schema)
35
+ 2. [Configure session/authentication](#sessions-and-authentication)
36
+ 3. [Make queries](#make-queries)
37
+
38
+ ### Dump the schema
39
+ One of the main benefits of GraphQL is its [schema and type system](https://graphql.org/learn/schema/)
40
+ which enables tools like graphql-client to ensure your queries are valid in development.
41
+
42
+ So the first step in making GraphQL queries is having a local JSON file of Shopify's Admin schema.
43
+ This gem provides a `shopify_api:graphql:dump` Rake task to make it as easy as possible:
44
+
45
+ #### Private apps
46
+ ```bash
47
+ $ rake shopify_api:graphql:dump SHOP_URL="https://API_KEY:PASSWORD@SHOP_NAME.myshopify.com" API_VERSION=2020-01
48
+ ```
49
+ #### Public apps
50
+ ```bash
51
+ $ rake shopify_api:graphql:dump SHOP_DOMAIN="SHOP_NAME.myshopify.com" ACCESS_TOKEN="SHOP_TOKEN" API_VERSION=2020-01
52
+ ```
53
+
54
+ If successful `db/shopify_graphql_schemas/2020-01.json` will be created.
55
+
56
+ You can either use private app authentication or an OAuth access token. Run `rake shopify_api:graphql:dump`
57
+ to see full usage details.
58
+
59
+ If you're using shopify_api in a Rails app, the default location for schema files is `db/shopify_graphql_schemas`.
60
+ For non-Rails applications, the default is `shopify_graphql_schemas` in your project root.
61
+
62
+ The schema path location can be changed via `ShopifyAPI::GraphQL.schema_location`:
63
+
64
+ ```ruby
65
+ ShopifyAPI::GraphQL.schema_location = 'assets/schemas'
66
+ ```
67
+
68
+ #### Updating schemas
69
+ Each time you want to use a new API version, or update an existing one
70
+ (such as the `unstable` version), simply run the Rake task again to overwrite the file.
71
+
72
+ ### Sessions and authentication
73
+ The GraphQL client is designed to be integrated with the rest of shopify_api so
74
+ all its features such as sessions, authentication, and API versioning work the
75
+ exact same.
76
+
77
+ If you've already been using the shopify_api gem in your application to make
78
+ REST API calls then no other configuration is necessary.
79
+
80
+ Steps 1-5 of our main [Getting started](https://github.com/Shopify/shopify_api#getting-started)
81
+ section still apply for the GraphQL client as well.
82
+
83
+ ### Make queries
84
+ Now that you've dumped a schema file and configured an authenticated session, you can make GraphQL API requests.
85
+ graphql-client encourages all queries to be defined statically as constants:
86
+
87
+ ```ruby
88
+ SHOP_NAME_QUERY = ShopifyAPI::GraphQL.client.parse <<-'GRAPHQL'
89
+ {
90
+ shop {
91
+ name
92
+ }
93
+ }
94
+ GRAPHQL
95
+
96
+ result = ShopifyAPI::GraphQL.client.query(SHOP_NAME_QUERY)
97
+ result.data.shop.name
98
+ ```
99
+
100
+ But we've also enabled its `allow_dynamic_queries` option if you prefer:
101
+
102
+ ```ruby
103
+ query = ShopifyAPI::GraphQL.client.parse <<-'GRAPHQL'
104
+ {
105
+ shop {
106
+ name
107
+ }
108
+ }
109
+ GRAPHQL
110
+
111
+ result = ShopifyAPI::GraphQL.client.query(query)
112
+ result.data.shop.name
113
+ ```
114
+
115
+ See the [graphql-client documentation](https://github.com/github/graphql-client#defining-queries)
116
+ for more details on defining and executing queries.
117
+
118
+ ## Rails integration
119
+ `ShopifyAPI::GraphQL` integrates with Rails to automatically do the following:
120
+
121
+ * load the `shopify_api:graphql:dump` Rake task
122
+ * set the `schema_location` to be in the `db` directory in your Rails root
123
+ * initialize clients in the Rails app initializer phase
124
+
125
+ ## API versioning
126
+ `ShopifyAPI::GraphQL` is version aware and lets you easily make queries to multiple
127
+ API versions through version specific clients if need be.
128
+
129
+ If you have multiple clients and need to be explicit you can specify the version parameter:
130
+
131
+ ```ruby
132
+ ShopifyAPI::GraphQL.client # defaults to the client using ShopifyAPI::Base.api_version
133
+ ShopifyAPI::GraphQL.client('unstable')
134
+ ```
135
+
136
+ ## Initialization process
137
+ `ShopifyAPI::GraphQL` is a thin integration layer which initializes `GraphQL::Client`s
138
+ from local schema files.
139
+
140
+ `ShopifyAPI::GraphQL.initialize_clients` scans `ShopifyAPI::GraphQL.schema_location`
141
+ and creates a client for each version specific schema file found.
142
+
143
+ This happens automatically in a Rails application due to our [integration](#rails-integration).
144
+ For non-Rails applications, ensure you call `ShopifyAPI::GraphQL.initialize_clients`
145
+ during your boot process.
146
+
147
+ The goal is to have all clients created at boot so there's no schema loading,
148
+ parsing, or client instantiation done during runtime when your app serves a request.
149
+
150
+
151
+ ## Using a custom GraphQL Client
152
+ By default `ShopifyAPI::GraphQL` wraps the Github GraphQL Client library. However, this client
153
+ may not suitable for various reasons. If you wish to expand on the interface of the client or
154
+ improve the required functions for your use case you can implement a client of your own.
155
+
156
+ To use a custom GraphQL Client:
157
+ ```
158
+ class CustomGraphQLClient < ::GraphQL::Client
159
+ end
160
+
161
+ ShopifyAPI::GraphQL.graphql_client = CustomGraphQLClient
162
+ ```
163
+
164
+
165
+ ## Using a custom query execution adapter
166
+ Github's GraphQL Client uses an adapter pattern so that you can define how you interact
167
+ with GraphQL API's. Shopify provides a minimal implementation in `ShopifyAPI::GraphQL::HTTPClient`.
168
+ If you need to add additional functionality pre, during or post query execution you can
169
+ consider implementing these within a custom query execution adapter, inheriting from
170
+ `ShopifyAPI::GraphQL::HTTPClient` which provides the necessary implementation for
171
+ headers, url, and api versions
172
+
173
+
174
+ To set a custom query executiona dapter set `ShopifyAPI::GraphQL.execution_adapter` to your client:
175
+ ```ruby
176
+ class RaisingHTTPClient < ShopifyAPI::GraphQL::HTTPClient
177
+ def execute(document:, operation_name: nil, variables: {}, context: {})
178
+ result = super
179
+ do_work(result)
180
+ end
181
+
182
+ private
183
+
184
+ def do_work(result)
185
+ result
186
+ end
187
+ end
188
+
189
+ ShopifyAPI::GraphQL.execution_adapter = RaisingHTTPClient
190
+ ```
191
+
192
+ Note, the execution adapter has `client` in the name. This is to remain consistent with
193
+ the naming conventions within the Github GraphQL Client library.
194
+
195
+ ## Migration guide
196
+ Prior to shopify_api v9.0 the GraphQL client implementation was limited and almost
197
+ unusable due to the client making dynamic introspection queries to Shopify's API.
198
+ This was not only very slow but also led to unbounded memory growth.
199
+
200
+ There are two steps to migrate to the new client:
201
+ 1. [Dump a local schema file](#dump-the-schema)
202
+ 2. [Migrate `client` usage](#migrate-usage)
203
+
204
+ ### Migrate usage
205
+
206
+ Previously a client was initialized with `ShopifyAPI::GraphQL.new`:
207
+ ```ruby
208
+ client = ShopifyAPI::GraphQL.new
209
+
210
+ SHOP_NAME_QUERY = client.parse <<-'GRAPHQL'
211
+ {
212
+ shop {
213
+ name
214
+ }
215
+ }
216
+ GRAPHQL
217
+
218
+ result = client.query(SHOP_NAME_QUERY)
219
+ result.data.shop.name
220
+ ```
221
+
222
+ Now there's no need to initialize a client so all references to
223
+ `ShopifyAPI::GraphQL.new` should be removed and instead the client is called
224
+ via `ShopifyAPI::GraphQL.client`:
225
+
226
+ ```ruby
227
+ client = ShopifyAPI::GraphQL.client
228
+
229
+ SHOP_NAME_QUERY = client.parse <<-'GRAPHQL'
230
+ {
231
+ shop {
232
+ name
233
+ }
234
+ }
235
+ GRAPHQL
236
+
237
+ result = client.query(SHOP_NAME_QUERY)
238
+ result.data.shop.name
239
+ ```
240
+
241
+ See [make queries](#make-queries) for more usage details.