//so data comes back from API as an object//
async function fetchSanityData(){
const response = await fetch(sanityUrl, {
method: "POST",
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify({ query: sanityQuery})
})
const { data } = await response.json()
console.log(data)
sanityData = data
}
Today I learned
How to use the graphql API in sanity to query and return our menu data that we had uploaded:
const sanityUrl = 'https://6buksnvq.api.sanity.io/v1/graphql/production/default' //THIS IS THE LINK FROM RUNNING NPX SANITY GRAPH QL//
const sanityQuery =
query { allCategory{ name primaryImage{ asset{ url } } carouselImage{ asset{ url } } } }
Then, we fetch the sanity data:
//so data comes back from API as an object// async function fetchSanityData(){ const response = await fetch(sanityUrl, { method: "POST", headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' }, body: JSON.stringify({ query: sanityQuery}) }) const { data } = await response.json() console.log(data) sanityData = data }