Can I use the JavaScript Buy SDK or query/mutate with GraphQL from within the theme liquid files?

Hi @Nortski ,

You can try this code. It’s working on my site.

const productQuery = `
  query {
      products( first: 10) {
        edges{
          node {
            id
            handle
            title
	
            variants(first: 10){
              edges{
                node{
                  title
              }
            }
          }
        }
      }  
    }
}
`;

const STOREFRONT_ACCESS_TOKEN =  'xxxxxxxxxxx'
const GRAPHQL_URL = '/api/2021-07/graphql.json'
  
fetch(GRAPHQL_URL, {
    method: "POST",
    headers: {
      'Content-Type': 'application/graphql',
      "X-Shopify-Storefront-Access-Token": STOREFRONT_ACCESS_TOKEN
    },
    body: productQuery
  })
  .then(res => res.json())
  .then(result => {
   
  });

Hope it helps.