rbi-learning / Today-I-Learned

1 stars 0 forks source link

08/19 Official Notes #158

Open Stommy123 opened 4 years ago

Stommy123 commented 4 years ago

08/19 Day 18 Lecture Notes

Review of Morning Exercise

GQL

query {
  allCategory {
    _id
    name
    primaryImage {
      assert {
        url
      }
    }
  }
}

Lecture

Fetching with GQL

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)

Sanity