Issue with a new field not being available in GraphQL API after updating in Sanity.io
12 replies
Last updated: Aug 11, 2020
R
I added a new field in fields array in siteSettings document and updated it's value with studio. But the field is not available in graphQL API.
What could be the issue? I did close the process and rebuild the gatsby site after updating.
EDIT: Solved
{ name: 'siteURL', type: 'url', title: 'Site URL', description: 'Provide URL for your website.' },
EDIT: Solved
Aug 11, 2020, 4:05 PM
P
Hi Rahul, did you deploy your GraphQL API after adding the new field? You can do so by running
sanity graphql deployin the CLI 🙂
Aug 11, 2020, 4:11 PM
R
user M
It throws an error- Checking for deployed API
Error: Request returned HTTP 401
at D:/WebDev Projects/Gatsby/The Gatsby Blog/Sanity Blog Studio/node_modules/@sanity/core/lib/util/getUrlHeaders.js:30:21
at f (D:/WebDev Projects/Gatsby/The Gatsby Blog/Sanity Blog Studio/node_modules/once/once.js:25:25)
at ClientRequest.<anonymous> (D:/WebDev Projects/Gatsby/The Gatsby Blog/Sanity Blog Studio/node_modules/simple-get/index.js:63:5)
Aug 11, 2020, 4:30 PM
P
Could you run
sanity logout && sanity loginand then try once again?
401indicates an authentication issue in this case.
Aug 11, 2020, 4:32 PM
R
I did, and now it says I need a top-level scheme to deploy.
post.js
bodyportableText.js
Error: Encountered anonymous inline code at index 2 for type/field Post/body.
post.js
{ name: 'body',
type: 'bodyPortableText',
title: 'Body'
}
bodyportableText.js
_export_ _default_ {
name: 'bodyPortableText',
type: 'array',
title: 'Post body',
of: [
{
type: 'block',
title: 'Block',
_// Styles let you set what your user can mark up blocks with. These_
// corrensponds with HTML tags, but you can set any title or value
// you want and decide how you want to deal with it where you want to
// use your content.
styles: [
{ title: 'Normal', value: 'normal' },
{ title: 'H1', value: 'h1' },
{ title: 'H2', value: 'h2' },
{ title: 'H3', value: 'h3' },
{ title: 'H4', value: 'h4' },
{ title: 'Quote', value: 'blockquote' }
],
lists: [
{ title: 'Bullet', value: 'bullet' },
{ title: 'Number', value: 'number' }
],
// Marks let you mark up inline text in the block editor.
marks: {
// Decorators usually describe a single property – e.g. a typographic
// preference or highlighting by editors.
decorators: [
{ title: 'Strong', value: 'strong' },
{ title: 'Emphasis', value: 'em' },
{ title: 'Underline', value: 'underline' },
{ title: 'Strike', value: 'strike-through' }
],
// Annotations can be any object structure – e.g. a link or a footnote.
annotations: [
{
name: 'link',
type: 'object',
title: 'URL',
fields: [
{
title: 'URL',
name: 'href',
type: 'url'
},
{
title: 'Open externally',
name: 'blank',
type: 'boolean'
}
]
},
{
name: 'internalLink',
type: 'object',
title: 'Internal Link',
blockEditor: {
_icon: () =>_ ':link:'
},
fields: [
{
name: 'link',
type: 'string',
description: 'Paste only the slug for post eg: "my-first-post"'
}
]
}
]
},
of: [{ type: 'authorReference' }]
},
_// You can add additional types here. Note that you can't use_
// primitive types such as 'string' and 'number' in the same array
// as a block type.
{
type: 'mainImage',
_options: { hotspot: true_ }
},
{
name: 'myCode',
title: 'Code Editor',
description: 'Code editor',
type: 'code'
}
]
}
Aug 11, 2020, 4:35 PM
R
I am using the Sanity blog starter template
user M
Aug 11, 2020, 4:36 PM
P
Just tested locally to be sure, but that template does indeed deploy a GraphQL API out-of-the-box. Did you perhaps add any new objects to your schema that are declared inline (within another document type) instead of at the top level? Here’s some additional information on the error you are seeing: https://www.sanity.io/docs/graphql#strict-schemas-33ec7103289a .
Please feel free to share your schema folder or a link to your repo (in DM if you prefer) so I can have a look
🙂
Please feel free to share your schema folder or a link to your repo (in DM if you prefer) so I can have a look
🙂
Aug 11, 2020, 5:19 PM
R
user M
Yes, I have added a few fields and object. but can't seem to figure out which object needs to be top-level. I can DM you the repo linkAug 11, 2020, 5:21 PM
P
Ah I see, you’ll have to “hoist” your
And then include this as follows in `bodyPortableText`:
And add it to your
codetype field in
bodyPortableTextto the top level. To do so, the most simple way is probably to create a new object called `myCode.js`:
export default { name: 'myCode', title: 'Code Editor', description: 'Code editor', type: 'code' }
... { type: 'myCode' }
schema.jsfile:
... import myCode from './objects/myCode' ... export default createSchema({ ... types: schemaTypes.concat([ ... myCode ... ]) })
Aug 11, 2020, 6:53 PM
R
user M
Thank you so much ❤️Aug 11, 2020, 7:29 PM
R
I was looking for issues in an 'object' and completely missed out on the code component!!
Aug 11, 2020, 7:29 PM
R
Thanks a lot!
Aug 11, 2020, 7:29 PM
P
It's easy to miss, especially hidden like that inside the portable text array. Glad to hear it's working! 🚀
Aug 11, 2020, 8:09 PM
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.