GraphQL with Gatsby - Update Slug from String to Slug Type Fails
23 replies
Last updated: May 18, 2022
A
Having issue with Graphql in Gatsby, after I update the slug type from string to slug type. My graphql still fails
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
Field "slug" must not have a selection since type "String" has no subfields
sanity deployagain after publishing the changes ( generating slugs )?** I already run the
sanity graphql deployas well
May 16, 2022, 10:34 AM
K
It looks like you might be doing
slug { current }somewhere, but your field is
stringtype, which is why it cannot be queried like this.
May 16, 2022, 11:09 AM
A
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
K
Updating the schema does not update your documents. Your documents still have a string has a
slugfield. You’ll need to perform a data migration to convert them to the right shape.
May 16, 2022, 11:47 AM
A
yes, I did that already in the Sanity Study, to have a proper slug.
May 16, 2022, 12:32 PM
A
if I query into the sanity vision it returns correct value
slug { _type: "" _current: "" }
May 16, 2022, 12:33 PM
K
That doesn’t seem correct to me?
May 16, 2022, 12:34 PM
K
A slug object should be
{ current: "your-value" }.
May 16, 2022, 12:35 PM
A
sorry its like this
"slug":{ "_type":"slug" "current":"python-testing"}
May 16, 2022, 12:35 PM
K
Pretty sure the
_typekey is not a thing on a slug object, but that shouldn’t matter for your query.
May 16, 2022, 12:36 PM
K
Are all your documents okay?
May 16, 2022, 12:36 PM
A
yes, no error I was able to publish them as well ( using sanity studio )
May 16, 2022, 12:36 PM
A
I’m thinking do I need to run
sanity deployagain after publishing the updated data?
May 16, 2022, 12:37 PM
K
Shouldn’t need to.
May 16, 2022, 12:39 PM
A
Is there a way I can tell what dataset the Sanity Studio currently using?
May 16, 2022, 12:57 PM
K
It should be defined in your sanity.json.
May 16, 2022, 1:18 PM
A
how about in the GUI?
May 16, 2022, 1:23 PM
K
Mmmh. Not easily. You can check the Network tabs for the requests. They contain the dataset name.
May 16, 2022, 1:28 PM
A
Thanks
May 16, 2022, 1:38 PM
So, the following does look like the correct data format for your slug:
Maybe try running
"slug":{ "_type":"slug" "current":"python-testing"}
sanity graphql undeploythen
sanity graphql deployto see if that helps?
May 16, 2022, 4:32 PM
A
will this delete my dataset?
May 17, 2022, 12:40 AM
A
>...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
A
Thanks! works now I did what you suggested to
undeploythen
deploythe sanity graphql 🙂
May 18, 2022, 3:02 AM
Sanity– build remarkable experiences at scale
Sanity is a 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.