All Projects → malomohq → shopify-graphql-elixir

malomohq / shopify-graphql-elixir

Licence: MIT license
Elixir client for the Shopify GraphQL Admin API

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to shopify-graphql-elixir

shopify-development-resources
A List of resources for Shopify development
Stars: ✭ 56 (+211.11%)
Mutual labels:  shopify, shopify-apps, shopify-api
shopapp-shopify-ios
A Shopify provider for a ShopApp for iOS application
Stars: ✭ 49 (+172.22%)
Mutual labels:  shopify, shopify-apps, shopify-api
shopify-app-starter-kit
Shopify app starter kit written in Ruby on Rails w/ appropriate tools to get your Shopify app up and running quickly 🚀
Stars: ✭ 42 (+133.33%)
Mutual labels:  shopify, shopify-apps, shopify-api
oauth2-shopify-php
Shopify Provider for the OAuth 2.0 Client
Stars: ✭ 14 (-22.22%)
Mutual labels:  shopify, shopify-api
shopify-node-react-app
Shopify paid app in Node.js & React.js that connects to a store and lets merchants select products to automatically discount them in the Shopify admin interface.
Stars: ✭ 29 (+61.11%)
Mutual labels:  shopify, shopify-api
bold-shopify-toolkit
A Symfony Based Shopify api wrapper
Stars: ✭ 24 (+33.33%)
Mutual labels:  shopify, shopify-api
shopify-node-express-app
Simple Shopify app with Express and Node.js that connects to a Shopify store via OAuth.
Stars: ✭ 20 (+11.11%)
Mutual labels:  shopify, shopify-api
shopify-next.js-tailwind
Learn the Shopify + Next.js + Tailwind CSS Stack! SWR, Hydrogen, + more
Stars: ✭ 227 (+1161.11%)
Mutual labels:  shopify, shopify-api
mechanic-tasks
Public task repository for Mechanic (https://mechanic.dev)
Stars: ✭ 42 (+133.33%)
Mutual labels:  shopify, shopify-api
next-shopify-starter
Nextjs + Tailwind CSS + Shopify Starter
Stars: ✭ 385 (+2038.89%)
Mutual labels:  shopify, shopify-api
gulp-shopify
Blank slate Shopify theme for Developers, packaged with Gulp.js for processing SCSS, JavaScript (ES6), images and fonts. Made to support Online Store 2.0 features and Shopify CLI.
Stars: ✭ 142 (+688.89%)
Mutual labels:  shopify
vscode-liquid
💧Liquid language support for VS Code
Stars: ✭ 137 (+661.11%)
Mutual labels:  shopify
ShopifyScripts
Various Shopify scripts to generate XML product feeds, remarketing tracking for Google Ads, and others.
Stars: ✭ 98 (+444.44%)
Mutual labels:  shopify
bootstrap-shopify-theme
🛍 A free Shopify Theme built with Bootstrap, BEM, Liquid, Sass, ESNext, Theme Tools, ... and Webpack.
Stars: ✭ 41 (+127.78%)
Mutual labels:  shopify
shopify
Vue Storefront 2 integration for Shopify
Stars: ✭ 109 (+505.56%)
Mutual labels:  shopify
flutter simple shopify
No description or website provided.
Stars: ✭ 83 (+361.11%)
Mutual labels:  shopify
interledger-payment-app-example
An implementation of the Interledger spec through an Android's Payment App
Stars: ✭ 26 (+44.44%)
Mutual labels:  shopify
MugglePay
Make Crypto Payment Easy 让数字货币支付更简单
Stars: ✭ 176 (+877.78%)
Mutual labels:  shopify
polaris-vue
Polaris Vue by HulkApps is a component library for Vue.js based on Shopify Polaris style guide.
Stars: ✭ 39 (+116.67%)
Mutual labels:  shopify
monitor
Community restock monitor template
Stars: ✭ 78 (+333.33%)
Mutual labels:  shopify

Shopify.GraphQL

Actions Status

Installation

shopify_graphql is published on Hex. Add it to your list of dependencies in mix.exs:

def deps do
  [
    {:shopify_graphql, "~> 2.0.0-rc.5"}
  ]
end

You are also required to specify an HTTP client and JSON codec as dependencies. shopify_graphql supports hackney and jason out of the box.

Usage

You can make a request to the Shopify GraphQL admin API by passing a query to the Shopify.GraphQL.send/2 function.

query =
  """
  {
    shop {
      name
    }
  }
  """

Shopify.GraphQL.send(query, access_token: "...", shop: "myshop"))

You can manage variables using the Shopify.GraphQL.put_variable/3 and Shopify.GraphQL.put_variables/2 functions.

query =
  """
  {
    query GetCustomer($customerId: ID!) {
      customer(id:$customerId)
    }
  }
  """

query
|> Shopify.GraphQL.put_variable(:customerId, "gid://shopify/Customer/12195007594552")
|> Shopify.GraphQL.send(access_token: "...", shop: "myshop")

query
|> Shopify.GraphQL.put_variables(%{customerId: "gid://shopify/Customer/12195007594552"})
|> Shopify.GraphQL.send(access_token: "...", shop: "myshop")

Configuration

All configuration must be provided on a per-request basis as a keyword list to the second argument of Shopify.GraphQL.send/2.

  • :access_token - Shopify access token for making authenticated requests
  • :endpoint - endpoint for making GraphQL requests. Defaults to graphql.json.
  • :http_client - the HTTP client used for making requests. Defaults to Shopify.GraphQL.Client.Hackney.
  • :http_client_opts - additional options passed to :http_client. Defaults to [].
  • :http_headers - a list of additional headers to send when making a request. Example: [{"x-graphql-cost-include-fields", "true"}]. Defaults to [].
  • :http_host - HTTP host to make requests to. Defaults to myshopify.com. Note that using :host rather than a combination of :host and :shop may be more convenient when working with public apps.
  • :http_path - path to the admin API. Defaults to admin/api.
  • :http_port - the HTTP port used when making requests
  • :http_protocol - the HTTP protocol when making requests. Defaults to https.
  • :json_codec - codec for encoding and decoding JSON payloads
  • :limiter - whether to use the limiter to manage Shopify rate limiting. May be true, false or an atom. If false the limiter will not be used. If true the limiter will be used and the default name Shopify.GraphQL.Limiter will be used to interact with the limiter process. If an atom is used the limiter will be used and the atom will be used to interact with the limiter process. Defaults to false.
  • :limiter_opts - additional options used with :limiter. Defaults to [].
    • :max_requests - the maximum number of concurrent requests per shop. Defaults to 3.
    • :monitor - whether to monitor a limiter. When set to true the limiter process will be stopped after a certain period of time of inactivity in order to keep limiter process size to a minimum. When set to false the limiter process will not stop and will stay alive indefinitely. Default true.
    • :monitor_timeout - number of miliseconds to check for inactivity before stopping a partition
    • :restore_to - the minimum cost to begin making requests again after being throttled. Possible values are :half, :max or an integer. Defaults to :half.
  • :retry - module implementing a strategy for retrying requests. Disabled when set to false. Defaults to false
  • :retry_opts - options for configuring retry behavior. Defaults to [].
    • :max_attempts - the maximum number of retries. Defaults to 3.
  • :shop - name of the shop that a request is being made to
  • :version - version of the API to use. Defaults to nil. According to Shopify, when not specifying a version Shopify will use the oldest stable version of its API.

Rate Limiting

shopify_graphql provides the ability to automatically manage the rate limiting of Shopify's GraphQL admin API. We do this using what's called a limiter. The limiter will automatically detect when queries are being rate limited and begin managing the traffic sent to Shopify to ensure queries get executed.

The limiter is an optional feature of shopify_graphql. To use it you will need to add gen_stage as a dependency to your application.

You will then need to add Shopify.GraphQL.Limiter to your supervision tree. When starting the limiter you may optionally pass a :name argument. If the :name argument is used the process will use that value as it's name.

To send queries through the limiter you will need to pass the limiter: true config value to Shopify.GraphQL.send/2.

Example

Shopify.GraphQL.send(query, access_token: "...", limiter: true, shop: "myshop")

If you named your process something other than Shopify.GraphQL.Limiter you will need to pass the name of the process to the :limiter config option instead of true.

Retries

shopify_graphql has a built-in mechanism for retrying requests that either return an HTTP status code of 500 or a client error. You can enabled retries by providing a module that implements the Shopify.GraphQL.Retry behaviour to the :retry option when calling Shopify.GraphQL.send/2.

Currently, shopify_graphql provides a Shopify.GraphQL.Retry.Linear strategy for retrying requests. This strategy will automatically retry a request on a set interval. You can configure the interval by adding :retry_in with the number of milliseconds to wait before sending another request to the :retry_opts option.

Example

Shopify.GraphQL.send("{ shop { name } }", access_token: "...", retry: Shopify.GraphQL.Retry.Linear, retry_opts: [retry_in: 250], shop: "myshop")

The example above would retry a failed request after 250 milliseconds. By default Shopify.GraphQL.Retry.Linear will retry a request immediately if :retry_in has no value

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].