Open a-krolak opened 4 years ago
Today I Learned...
GraphQL
sanity graphql deploy
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)
query { allCategory { _id name primaryImage { assert { url } } } }
Today I Learned...
GraphQL
sanity graphql deploy
allows you to create a gql endpoint for your sanity projectHow 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)