简体   繁体   中英

GraphQL implimentation with Shopify using Java

I am building a Shopify app which needs to adjust inventory of products in Shopify. Shopify is about to deprecate its inventory adjustment POST call using admin/product.json and will updated to /admin/inventory_levels/adjust.json , but the new inventory adjustment POST call allows to update only single inventory level at a time. But my app needs to update multiple inventory levels at some particular point of time, so doing POST call for every individual inventory level will be resource taking and time consuming. When I contacted a Shopify Expert, he recommended me to use GraphQL for the above purpose. I researched for GraphQL + Shoipfy implementation in Java but did not find satisfactory results, so I need help in implementing Client POST call of GraphQL in Java . Below is my structure of GraphQL, I want to implement in Java

mutation {
  item1: inventoryAdjustQuantity(input: {inventoryLevelId: "gid://shopify/InventoryLevel/9229566067?inventory_item_id=10588945219699", availableDelta: 3}) {
    inventoryLevel {
      available
    }
    userErrors {
      field
      message
    }
  }
  item2: inventoryAdjustQuantity(input: {inventoryLevelId: "gid://shopify/InventoryLevel/9229762675?inventory_item_id=10588945219699", availableDelta: 3}) {
    inventoryLevel {
      available
    }
    userErrors {
      field
      message
    }
  }
  item3: inventoryAdjustQuantity(input: {inventoryLevelId: "gid://shopify/InventoryLevel/9229926515?inventory_item_id=10588945219699", availableDelta: 3}) {
    inventoryLevel {
      available
    }
    userErrors {
      field
      message
    }
  }
  item4: inventoryAdjustQuantity(input: {inventoryLevelId: "gid://shopify/InventoryLevel/9645391987?inventory_item_id=10588945219699", availableDelta: 3}) {
    inventoryLevel {
      available
    }
    userErrors {
      field
      message
    }
  }
  item5: inventoryAdjustQuantity(input: {inventoryLevelId: "gid://shopify/InventoryLevel/9645457523?inventory_item_id=10588945219699", availableDelta: 3}) {
    inventoryLevel {
      available
    }
    userErrors {
      field
      message
    }
  }
  item6: inventoryAdjustQuantity(input: {inventoryLevelId: "gid://shopify/InventoryLevel/9645490291?inventory_item_id=10588945219699", availableDelta: 3}) {
    inventoryLevel {
      available
    }
    userErrors {
      field
      message
    }
  }
  item7: inventoryAdjustQuantity(input: {inventoryLevelId: "gid://shopify/InventoryLevel/9229566067?inventory_item_id=10588945252467", availableDelta: 3}) {
    inventoryLevel {
      available
    }
    userErrors {
      field
      message
    }
  }
  item8: inventoryAdjustQuantity(input: {inventoryLevelId: "gid://shopify/InventoryLevel/9229762675?inventory_item_id=10588945252467", availableDelta: 3}) {
    inventoryLevel {
      available
    }
    userErrors {
      field
      message
    }
  }
  item9: inventoryAdjustQuantity(input: {inventoryLevelId: "gid://shopify/InventoryLevel/9229926515?inventory_item_id=10588945252467", availableDelta: 3}) {
    inventoryLevel {
      available
    }
    userErrors {
      field
      message
    }
  }
  item10: inventoryAdjustQuantity(input: {inventoryLevelId: "gid://shopify/InventoryLevel/9645391987?inventory_item_id=10588945252467", availableDelta: 3}) {
    inventoryLevel {
      available
    }
    userErrors {
      field
      message
    }
  }
}

It would be great if you will help me with this issue or will guide me to some resourceful link.

You can use graphql admin app to run you queries in app. It is very good app it also help you to find the parameters as well as identify you error in query. https://shopify-graphiql-app.shopifycloud.com/login

You can also visit document to describe how we can use insomnia -> graphql learning kit. Where you need import the collection. I am using this tool to run graphql. https://www.shopify.com/partners/blog/shopify-graphql-learning-kit

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM