Search code examples
phpherokugraphqlshopifyshopify-api

Heroku App crashing when calling shopify graphql api in forloop


I have created a Heroku app that uses Graphql API on Shopify, on a product level, it has no problem returning the data, but on variants, since this is where I need to have the mutation, I added the graphql code inside for loop and it crash, please let me know how I can improve it, or how I improved it so it won't crash. by the way, I used PHP if that helps

This is the product level graphql

enter image description here

This is where I add the for loop and mutation

enter image description here


Solution

  • Your question is nearly impossible to answer. You provide no debugging clues. Your query is a bit strange as you ask for only half the variants, (first: 50) with no effort the get the last 50. A smart organization might be:

    • ask for the variants and the metafield you want directly in the query
    • use cursors to page through the variants.

    There is no need to make API calls per variant here. You can of course, but why bother.

    Log your responses. Shopify will tell you what error you making in GQL. Without your logs, no one can help you.