{"id":13878547,"url":"https://github.com/ScreenStaring/shopify_api_retry","last_synced_at":"2025-07-16T14:32:27.743Z","repository":{"id":56895379,"uuid":"195725559","full_name":"ScreenStaring/shopify_api_retry","owner":"ScreenStaring","description":"Retry a ShopifyAPI request if rate-limited or other errors occur. Works with the REST and GraphQL APIs.","archived":false,"fork":false,"pushed_at":"2021-12-24T04:30:44.000Z","size":27,"stargazers_count":13,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-25T02:40:59.301Z","etag":null,"topics":["graphql","http-status-code","rate-limiting","ruby","shopify","shopify-api","shopify-app-development","shopify-graphql-api"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ScreenStaring.png","metadata":{"files":{"readme":"README.md","changelog":"Changes","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-08T02:50:51.000Z","updated_at":"2024-02-02T04:43:40.000Z","dependencies_parsed_at":"2022-08-21T01:20:48.978Z","dependency_job_id":null,"html_url":"https://github.com/ScreenStaring/shopify_api_retry","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScreenStaring%2Fshopify_api_retry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScreenStaring%2Fshopify_api_retry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScreenStaring%2Fshopify_api_retry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScreenStaring%2Fshopify_api_retry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ScreenStaring","download_url":"https://codeload.github.com/ScreenStaring/shopify_api_retry/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226138849,"owners_count":17579496,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graphql","http-status-code","rate-limiting","ruby","shopify","shopify-api","shopify-app-development","shopify-graphql-api"],"created_at":"2024-08-06T08:01:52.768Z","updated_at":"2024-11-24T07:31:07.525Z","avatar_url":"https://github.com/ScreenStaring.png","language":"Ruby","readme":"# Shopify API Retry\n\n![CI](https://github.com/ScreenStaring/shopify_api_retry/workflows/CI/badge.svg)\n\nSimple Ruby module to retry a [`ShopifyAPI` request](https://github.com/Shopify/shopify_api) if rate-limited or other errors\noccur. Works with the REST and GraphQL APIs.\n\n## Installation\n\nBundler:\n\n```rb\ngem \"shopify_api_retry\"\n```\n\nGem:\n\n```\ngem install shopify_api_retry\n```\n\n## Usage\n\n### REST API\n\nBy default requests are retried when a Shopify rate limit error (HTTP 429) is returned. The retry happens once after waiting for\n[the seconds given by the HTTP `Retry-After` header](https://shopify.dev/concepts/about-apis/rate-limits):\n```rb\nrequire \"shopify_api_retry\" # requires \"shopify_api\" for you\n\nShopifyAPIRetry::REST.retry { customer.update_attribute(:tags, \"foo\") }\ncustomer = ShopifyAPIRetry::REST.retry { ShopifyAPI::Customer.find(id) }\n```\n\nYou can override this:\n```rb\nShopifyAPIRetry::REST.retry(:wait =\u003e 3, :tries =\u003e 5) { customer.update_attribute(:tags, \"foo\")  }\n```\nThis will try the request 5 times, waiting 3 seconds between each attempt. If a retry fails after the given number\nof `:tries` the last error will be raised.\n\nYou can also retry requests when other errors occur:\n```rb\nShopifyAPIRetry::REST.retry \"5XX\" =\u003e { :wait =\u003e 10, :tries =\u003e 2 } do\n  customer.update_attribute(:tags, \"foo\")\nend\n```\nThis still retries rate limit requests, but also all HTTP 5XX errors.\n\nClasses can be specified too:\n```rb\nShopifyAPIRetry::REST.retry SocketError =\u003e { :wait =\u003e 1, :tries =\u003e 5 } do\n  customer.update_attribute(:tags, \"foo\")\nend\n```\n\nYou can also set [global defaults](#global-defaults).\n\n### GraphQL API\n\nBy default a retry attempt is made when your [GraphQL request is rate-limited](https://shopify.dev/concepts/about-apis/rate-limits#graphql-admin-api-rate-limits).\nIn order to calculate the proper amount of time to wait before retrying you must set the `X-GraphQL-Cost-Include-Fields` header\n(_maybe this library should do this?_):\n\n```rb\nrequire \"shopify_api_retry\" # requires \"shopify_api\" for you\n\nShopifyAPI::Base.headers[\"X-GraphQL-Cost-Include-Fields\"] = \"true\"\n```\n\nOnce this is set run your queries and mutations and rate-limited requests will be retried.\nThe retry happens once, calculating the wait time from the API's cost data:\n```rb\nresult = ShopifyAPIRetry::GraphQL.retry { ShopifyAPI::GraphQL.client.query(YOUR_QUERY) }\np result.data.whatever\n```\n\nTo calculate the retry time **the query's return value must be returned by the block**.\n\nYou can override the retry times:\n```rb\nresult = ShopifyAPIRetry::GraphQL.retry(:wait =\u003e 4, :tries =\u003e 4) do\n  ShopifyAPI::GraphQL.client.query(YOUR_QUERY)\nend\np result.data.whatever\n```\n\nLike retry attempts made with the REST API you can specify errors to retry but, due to the GraphQL specification, these must not\nbe HTTP status codes and are only relevant to network connection-related errors:\n\n```rb\nresult = ShopifyAPIRetry::GraphQL.retry SocketError =\u003e { :wait =\u003e 1, :tries =\u003e 5 } do\n  ShopifyAPI::GraphQL.client.query(YOUR_QUERY)\nend\n```\n\nTo give wait and try times for specifically for rate limit errors, use the key `:graphql`:\n```rb\nresult = ShopifyAPIRetry::GraphQL.retry :graphql =\u003e { :wait =\u003e 10, :tries =\u003e 5 } do\n  ShopifyAPI::GraphQL.client.query(YOUR_QUERY)\nend\n```\n\nNote that specifying a `:wait` via `:graphql` or without an error key will skip calculating the retry based on the API\nresponse's cost data.\n\n### Global Defaults\n\nYou can configure global defaults to be used by REST and GraphQL calls. For example:\n\n```rb\nShopifyAPIRetry.configure do |config|\n  config.default_wait  = 2.5\n  config.default_tries = 10\n\n  # Use default_* for these\n  config.on [\"5XX\", Net::ReadTimeout]\n\n  config.on SocketError, :tries =\u003e 2, :wait =\u003e 1\nend\n```\n\n## See Also\n\n- [`ShopifyAPI::GraphQL::Tiny`](https://github.com/ScreenStaring/shopify_api-graphql-tiny) - Lightweight, no-nonsense, Shopify GraphQL Admin API client with built-in retry.\n- [Shopify Development Tools](https://github.com/ScreenStaring/shopify-dev-tools) - Command-line program to assist with the development and/or maintenance of Shopify apps and stores\n\n## License\n\nReleased under the MIT License: www.opensource.org/licenses/MIT\n\n---\n\nMade by [ScreenStaring](http://screenstaring.com)\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FScreenStaring%2Fshopify_api_retry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FScreenStaring%2Fshopify_api_retry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FScreenStaring%2Fshopify_api_retry/lists"}