GraphQL integration in Shopify apps

Ashok Damaniya


Jan 11, 2020
NEXT CASE STUDY >

Project summary

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.

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
Ashok Damaniya, Lead Full Stack ROR Developer @ Essence Solusoft
Sr. Ruby on Rails developer, Shopify APP & Theme Developer, ReactJS, AngularJS, EmberJS. A Workaholic, A reader, An addicted to learning new technologies, would love to help and encourage teammates, enthusiastic learners. Challenge acceptance attitude and discover the best of myself from it. Positive attitude toward failure and high goals setter.
ruby_on_rails

CONTACT US

We are open for new challenges and we help you reach your goals!