GraphQL fails after changing slug type from string to slug in Sanity

23 replies
Last updated: Jan 27, 2026
Having issue with Graphql in Gatsby, after I update the slug type from string to slug type. My graphql still fails
Field "slug" must not have a selection since type "String" has no subfields
I have already updated my Sanity Studio data and generate the slugs for it. Am I missing a step? I’m thinking maybe I need to run
sanity deploy
again after publishing the changes ( generating slugs )?** I already run the
sanity graphql deploy
as well
AI Update

I can help you with this! The issue you're experiencing is a common one when changing from a string type to a slug type in Sanity. The problem is that in GraphQL, when a field is a slug type, it becomes an object with subfields (specifically slug.current), not a plain string.

The Core Issue

When you query a slug field in GraphQL, you need to access the current property because Sanity's slug type is an object with this structure:

{
  "_type": "slug",
  "current": "your-slug-value"
}

How to Fix Your Gatsby Queries

You need to update your GraphQL queries in Gatsby. Change from:

{
  allSanityYourType {
    nodes {
      slug  // This won't work anymore
    }
  }
}

To:

{
  allSanityYourType {
    nodes {
      slug {
        current  // Access the current property
      }
    }
  }
}

About sanity graphql deploy

Yes, running sanity graphql deploy again is definitely necessary! This is a crucial step that many developers miss. According to the Sanity documentation, every time you update your Sanity schema (not just the content), you need to re-deploy the GraphQL API for the changes to be reflected.

Steps to Resolve:

  1. Run sanity graphql deploy from your studio folder to update the GraphQL schema
  2. Update all your Gatsby GraphQL queries to access slug.current instead of just slug
  3. If you're using the slug value in your code, update those references too (e.g., node.slug becomes node.slug.current)
  4. Restart your Gatsby development server

Note About Gatsby Integration

The gatsby-source-sanity plugin works by first fetching the GraphQL Schema Definitions from Sanity's deployed GraphQL API, which is why redeploying is essential. Without redeploying, Gatsby is still working with the old schema definition where slug was a string.

Running sanity deploy (for your Studio) is separate from sanity graphql deploy and won't update your GraphQL schema, so make sure you've run the GraphQL-specific deploy command.

Show original thread
23 replies

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.

Was this answer helpful?