Shopify Template Remix function not working

Topic summary

A developer is experiencing issues with a modified Shopify Remix template action function that isn’t working as expected.

Original vs. Modified Functionality:

  • Default template creates a random “snowboard” product
  • Modified version queries product variants, compares them with external endpoint data, and updates inventory quantities and prices via GraphQL mutations

Implementation Approach:

  • Fetches products from external source
  • Queries Shopify for matching variants by SKU
  • Compares prices and inventory levels
  • Builds update list for products with differences
  • Executes GraphQL mutations to update variants

Current Status:
The function appears incomplete or corrupted in the posted code—portions are reversed/garbled, making debugging difficult. The developer is seeking guidance on why the function fails to execute properly. No responses or solutions have been provided yet.

Summarized with AI on November 16. AI used: claude-sonnet-4-5-20250929.

Hello, I’m using a remix template from Shopify to create apps, by default the ‘action’ function creates a product called snowboard with colors and price generated randomly. So I updated this function to query a list of product variants and compare with the responses from my endpoint and update (mutation) the quantity in stock and the price of the products, but it seems that my function is not working. What should I do? Below is my function:

export async function action({ request }) {
const { admin } = await authenticate.admin(request);

const products = await getProducts();

// Lista de produtos que precisam ser atualizados
const productsToUpdate = ;

for (const product of products) {
const currentProduct = {
sku: product.idProduto,
title: product.descricao,
price: product.precoVendaSite,
inventoryQuantity: product.estoqueAtual,
};

const response = await admin.graphql(
query { productVariants(first: 1, query: "sku: ${currentProduct.sku}") { edges { node { id price inventoryQuantity } } } }
);

const responseJson = await response.json();
const shopifyPrice = responseJson.data.productVariants.nodes[0].price;
const shopifyStock = responseJson.data.productVariants.nodes[0].inventoryQuantity;

// Compare os preços e o estoque com os dados do endpoint
if (shopifyPrice !== currentProduct.price || shopifyStock !== currentProduct.inventoryQuantity) {
productsToUpdate.push({
id: responseJson.data.productVariants.nodes[0].id, // ID do produto na loja Shopify
price: currentProduct.price, // Novo preço a ser atualizado
inventoryQuantity: currentProduct.inventoryQuantity, // Nova quantidade em estoque a ser atualizada
});
}
}

// Execute uma mutation GraphQL para atualizar os produtos na loja Shopify
for (const productToUpdate of productsToUpdate) {
await admin.graphql(
mutation { productVariantUpdate( id: "${productToUpdate.id}", input: { price: "${productToUpdate.price}", inventoryQuantity: ${productToUpdate.inventoryQuantity} } ) { productVariant { id price inventoryQuantity } } }
);
}

console.log(‘Produtos atualizados com sucesso.’);

}