essence-header-logo

GraphQL integration in Shopify apps

Shopify App to manage the combo products. We were creating a single product by adding multiple products to that single combo product and manages the inventory when any combo product or individual product from that combo purchased by any user from any location of inventory.

case-study-3

Problem

We were using ShopifyAPI calls for performing create products and manage them, as ShopifyAPI has some limit to make API calls, it’s 40 requests per 2 seconds and we were making frequent requests for managing resources. And this API call limit was a headache to achieve concurrent results.

Solution

  • To Resolve this time-consuming API Calls we used GraphQL provided by Shopify. These are very lightweight response and quick also easy to structure calls with minimal required fields. With passing only those fields we require it to make calls faster than ever before and gives us freedom from API Rate Limit issue.

Solution Implementation

  • In that multiple combo_product_id available. So we passed id to product query and after that run query on product query.
def fetch_products
product_query(combo_product_id)
client.query(ProductQuery)
end
  • In that, we find out variant inventory item id and also find out metafields’ information using nodes that can indicate specific data. Kernel’s client parses the query and give data to the ProductQuery object.


def product_query(id)
query = <<-GRAPHQL
{
nodes(ids: #{id}) {
... on Product {
variants(first: 1){
edges{
node{
id
inventoryItem {
id
}
}
}
}
}
metafields(first: 10){
edges{
node{
key
value
}
}
}
}
}
GRAPHQL
Kernel.const_set(:ProductQuery, client.parse(query))
end

  • For finding client
def client
ShopifyAPI::GraphQL.new
end