By any chance would you have the request_id from that failing request? I can take a look into it for you. Thanks!
After a while doing some test and researching, we finally had to adjust or code to:
1. First, create the product with his variants using productCreate mutation.
2. Then, upload all media files (images) to the product and assign images to each variant.
After that, we have not experienced 502 Bad Gateway errors anymore.
It looks like Shopify have troubles handling mutations with too many variants/images.