Watch a live product demo 👀 See how Sanity powers richer commerce experiences

GraphQL with Gatsby - Update Slug from String to Slug Type Fails

23 replies
Last updated: May 18, 2022
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
May 16, 2022, 10:34 AM
It looks like you might be doing
slug { current }
somewhere, but your field is
string
type, which is why it cannot be queried like this.
May 16, 2022, 11:09 AM
yeah that’s what I thought so, but I already updated the fields to slug type so i can use
slug { current }
but somehow it still think it’s string so maybe cache?
May 16, 2022, 11:21 AM
Updating the schema does not update your documents. Your documents still have a string has a
slug
field. You’ll need to perform a data migration to convert them to the right shape.
May 16, 2022, 11:47 AM
yes, I did that already in the Sanity Study, to have a proper slug.
May 16, 2022, 12:32 PM
if I query into the sanity vision it returns correct value
slug {
  _type: ""
  _current: ""
}
May 16, 2022, 12:33 PM
That doesn’t seem correct to me?
May 16, 2022, 12:34 PM
A slug object should be
{ current: "your-value" }
.
May 16, 2022, 12:35 PM
sorry its like this
"slug":{
"_type":"slug"
"current":"python-testing"}
May 16, 2022, 12:35 PM
Pretty sure the
_type
key is not a thing on a slug object, but that shouldn’t matter for your query.
May 16, 2022, 12:36 PM
Are all your documents okay?
May 16, 2022, 12:36 PM
yes, no error I was able to publish them as well ( using sanity studio )
May 16, 2022, 12:36 PM
I’m thinking do I need to run
sanity deploy
again after publishing the updated data?
May 16, 2022, 12:37 PM
Shouldn’t need to.
May 16, 2022, 12:39 PM
Is there a way I can tell what dataset the Sanity Studio currently using?
May 16, 2022, 12:57 PM
It should be defined in your sanity.json.
May 16, 2022, 1:18 PM
how about in the GUI?
May 16, 2022, 1:23 PM
Mmmh. Not easily. You can check the Network tabs for the requests. They contain the dataset name.
May 16, 2022, 1:28 PM
Thanks
May 16, 2022, 1:38 PM
So, the following does look like the correct data format for your slug:
"slug":{
"_type":"slug"
"current":"python-testing"}
Maybe try running
sanity graphql undeploy
then
sanity graphql deploy
to see if that helps?
May 16, 2022, 4:32 PM
will this delete my dataset?
May 17, 2022, 12:40 AM
>...sanity graphql undeploy --dataset production
> ? Are you absolutely sure you want to delete the current GraphQL API connected to the "production" dataset?
May 17, 2022, 12:41 AM
It won't delete the dataset but it will delete the current GraphQL deployment. However, you're deploying a new one directly afterwards.
May 17, 2022, 6:46 PM
Thanks! works now I did what you suggested to
undeploy
then
deploy
the sanity graphql 🙂
May 18, 2022, 3:02 AM

Sanity– build remarkable experiences at scale

The Sanity Composable Content Cloud is the 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.

Related answers

Get more help in the community Slack

TopicCategoriesFeaturedRepliesLast Updated
After adding the subtitle and running this code npm run graphql-deploy It does nothingSep 15, 2020
how to limit a reference to just one entry in Studio reference input side versus the default as-many-entries-as-you-fill-in-an-array...Sep 18, 2020
Is it possible to fetch more than one "_type" using GROQ?Nov 2, 2020
I want to add a view with the Structure builder (S.view.component) where I list similar documents based on the title. What...Sep 23, 2020
Is there a structure builder example where the format of each preview for the document list is modified?Feb 3, 2021
I have an array of references to a country schema type but it always just returns NULL values for meJan 30, 2021
Hi, I need help with a query for getting the url of an image asset. Here is what I've been trying, but I only get the _ref...Dec 1, 2020
Sanity UI looks brilliant :smiley: Is something like the current date picker possible at the moment? I’m not sure if anicon...Dec 21, 2020
Hey everyone. I have been coding and may have potentially accidentally deleted something. Does anyone know how to resolve...Dec 26, 2020
Hello everyone and happy new year :raised_hands::skin-tone-2:, I have a problem with outputting Portable Text :disappointed:...Jan 1, 2021

Related contributions

Clean Next.js + Sanity app
- Template

Official(made by Sanity team)

A clean example of Next.js with embedded Sanity ready for recomposition.

Cody Olsen
Go to Clean Next.js + Sanity app

Blog with Built-in Content Editing
- Template

Official(made by Sanity team)

A Sanity-powered blog with built-in content editing and instant previews.

Go to Blog with Built-in Content Editing