Issue with schema update not reflecting on front end in GatsbyJS
This is a common caching issue with Gatsby! When you add new fields to your Sanity schema, Gatsby doesn't automatically pick them up because it caches the GraphQL schema and data from previous builds.
Here's what you need to do:
1. Run gatsby clean
This is the most important step. Run this command in your Gatsby project directory:
gatsby cleanThis clears Gatsby's cache and the .cache directory, forcing it to rebuild the GraphQL schema from scratch on the next build.
2. Redeploy your GraphQL API (if using GraphQL)
If you're using gatsby-source-sanity with the GraphQL API, you need to redeploy your schema:
cd your-sanity-studio
sanity graphql deployThis updates the GraphQL API that Gatsby queries to include your new field definitions.
3. Restart your Gatsby development server
After cleaning the cache, restart your dev server:
gatsby developWhy this happens:
The gatsby-source-sanity plugin fetches your Sanity GraphQL schema definitions and streams documents into Gatsby's in-memory datastore. When you add new fields, Gatsby's cached schema doesn't know about them until you clean the cache and rebuild.
Additional troubleshooting:
- Make sure the
stylefield is actually populated in your Sanity documents (not just in the schema) - If you're using
overlayDrafts: truein your gatsby-config.js, ensure you have a read token configured to see draft content - Check that your GraphQL queries in Gatsby actually include the new
stylefield
After running gatsby clean and restarting, your new style field should appear in your Gatsby queries!
Sanity – Build the way you think, not the way your CMS thinks
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.