rbi-learning / Today-I-Learned

1 stars 0 forks source link

Today I Learned (August 19) #159

Open a-krolak opened 4 years ago

a-krolak commented 4 years ago

Today I Learned...

GraphQL

How to Fetch with GQL

Example from lecture:

const sanityUrl = SANITY_URL const query = query { allCategory { _id name primaryImage { assert { url } } } } const response = await fetch(SANITY_URL, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Accept': 'application/json', } body: JSON.stringify({ query: sanityQuery }) }) const { data } = await response.json(); console.log(data.allCategory)