✨Discover storytelling in the AI age with Pixar's Matthew Luhn at Sanity Connect, May 8th—register now

Tips for accessing and previewing Sanity data in Gatsby

11 replies
Last updated: May 12, 2020
Is this an issue where Gatsby shows empty sanity children but the Sanity playground shows data?
May 12, 2020, 12:48 AM
If you want to access the sanity children you would need to query the
_raw
version of that field. So in your case,
_rawAmenities
and you’ll get the children.
May 12, 2020, 1:18 AM
Thank! you! Just got to that a couple minutes ago, it's working
May 12, 2020, 1:19 AM
Do you know any trick to fetch the data without the need to stop the Gatsby server?
May 12, 2020, 1:19 AM
On your gatsby-config. Add
watchMode: true
on your gatsby-sanity-source options. That should turn live preview!
May 12, 2020, 1:21 AM
Wow, thank you very much!
May 12, 2020, 1:21 AM
🙌
May 12, 2020, 1:21 AM
You can also show drafts by adding
overlayDrafts: true
more info from the source plugin: https://github.com/sanity-io/gatsby-source-sanity
May 12, 2020, 1:22 AM
It’s a really cool feature! It disciplined me to write code that doesn’t break the frontend if there is any missing data!
May 12, 2020, 1:23 AM
Nice, actually that's an excellent tip
write code that doesn't break the frontend if there is any missing data
May 12, 2020, 1:24 AM
Thank you
user N
May 12, 2020, 1:25 AM
You’re welcome! Happy to help1
May 12, 2020, 1:25 AM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?