Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Product price cannot be queried w/ graphQLClient #984

Open
4 tasks done
erichiggins opened this issue Jun 20, 2024 · 1 comment
Open
4 tasks done

The Product price cannot be queried w/ graphQLClient #984

erichiggins opened this issue Jun 20, 2024 · 1 comment

Comments

@erichiggins
Copy link

Bug details

Describe the bug

The Product Variant price cannot be queried when using the unoptimized UMD and graphQLClient.
I need to fetch a list of products, along with the following properties:

  • title
  • price
  • available for sale
  • inventory
  • tags

The optimized script does not provide inventory or tags, so I must use the unoptimized version.
However, when I try to add the Variant price field to my query, it causes the query to return zero results.

To Reproduce
Steps to reproduce the behaviour:

  1. Include the unoptimized UMD script
  2. Enable Headless on Shopify & grant appropriate permissions
  3. Define the client (w/ public token)
  4. Run the following code:

Code sample

  try {
    const productsQuery = client.graphQLClient.query((root) => {
      root.addConnection('products', {args: {first: 10}}, (product) => {
        console.log('product def', product);
        product.add('id');
        product.add('title');
        product.add('availableForSale');
        product.add('totalInventory');
        product.add('tags');
        product.addConnection('variants', { args: { first: 5 } }, (variant) => {
          console.log('variant def', variant);
          variant.add('id');
          variant.add('title');
          variant.add('availableForSale');
          variant.add('quantityAvailable');
          // NOTE: Breaks when this line is added. 
          variant.add('price');
        });
      }); 
    }); 
        
    // Call the send method with the custom products query
    client.graphQLClient.send(productsQuery).then(({model, data}) => {
      // NOTE: These both return `undefined`.
      console.log('model', model);
      console.log('data', data);
    });
  } catch (err) {
    console.log('err', err);
  }     

If I remove the following line, then the call returns the expected results.

variant.add('price');

Expected behavior
A clear and concise description of what you expected to happen.

The list of Products should be returned with the Variant prices included.

Environment (please complete the following information):

  • OS: MacOS
  • Browser: Chrome
  • SDK Version: v2.22.0

Additional context

I don't actually need Variants on my Products, but Shopify's API seems to always define price under Product Variant. I have tried adding a single variant as a workaround but it did not resolve this issue.

Bug Report Checklist

  • I have read and agree to the CODE_OF_CONDUCT.md
  • I have read the CONTRIBUTING.md guidelines.
  • I have provided a detailed description of the bug, including code samples, and/or network data.
  • I have provided information about my development environment, including SDK version.
@daniouyea
Copy link

Instead of variant.add('price'); try:

variant.add('priceV2', {alias: 'price'}, (price) => {
    price.add('amount');
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants