
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeNo worries, this is a common issue when setting up Sanity with Gatsby! The problem is that your GraphQL query works in Sanity's API playground, but Gatsby has its own separate GraphQL layer.
Here's what's happening: Sanity has its own GraphQL API (what you're testing in the playground), but Gatsby creates a completely different GraphQL schema by pulling data from various sources. To get Sanity data into Gatsby's GraphQL layer, you need to use the gatsby-source-sanity plugin.
Here's how to fix it:
npm install gatsby-source-sanitygatsby-config.js:module.exports = {
plugins: [
{
resolve: 'gatsby-source-sanity',
options: {
projectId: 'your-project-id',
dataset: 'production', // or your dataset name
// Optional: for draft preview
token: process.env.SANITY_TOKEN,
watchMode: true, // enables real-time updates in dev
},
},
],
}sanity graphql deploygatsby clean
gatsby developSanity:const {data} = useStaticQuery(graphql`
query getProjects {
allSanityProject {
nodes {
title
subtitle
description
mainImage {
asset {
url
}
}
tech
url
dates
}
}
}
`);Notice two changes:
allProject becomes allSanityProject (Gatsby adds the "Sanity" prefix)nodes { } for Gatsby's data structureAfter these steps, you should be able to access your projects data via data.allSanityProject.nodes in your component. The gatsby-source-sanity plugin is what bridges Sanity's content with Gatsby's GraphQL layer - that's why the query works in Sanity's playground but not directly in Gatsby!
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store