Making a BigCommerce GraphQL query with JavaScript
We recommend adding GraphQL queries to Stencil template front matter where possible. You can also make requests from JavaScript in your theme or in Script Manager.
See this example from BigCommerce:
fetch('/graphql', {
method: 'POST',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer {{ settings.storefront_api.token }}'
},
body: JSON.stringify({
query: `
query MyFirstQuery {
site {
settings {
storeName
}
products {
edges {
node {
name
sku
prices {
retailPrice {
value
currencyCode
}
price {
value
currencyCode
}
}
}
}
}
}
}
`
}),
})
.then(res => res.json())
.then(json => console.log(json));<br />