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.io – build remarkable experiences at scale

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