Go Behind the Experience to see how Tecovas brings the West to life with Sanity ūü§† July 18th

Issue with a new field not being available in GraphQL API after updating in Sanity.io

12 replies
Last updated: Aug 11, 2020
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.
{ name: 'siteURL',
      type: 'url',
      title: 'Site URL',
      description: 'Provide URL for your website.'
What could be the issue? I did close the process and rebuild the gatsby site after updating.

EDIT: Solved
Aug 11, 2020, 4:05 PM
Hi Rahul, did you deploy your GraphQL API after adding the new field? You can do so by running
sanity graphql deploy
in the CLI ūüôā
Aug 11, 2020, 4:11 PM
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
Could you run
sanity logout && sanity login
and then try once again?
indicates an authentication issue in this case.
Aug 11, 2020, 4:32 PM
I did, and now it says I need a top-level scheme to deploy.

Error: Encountered anonymous inline code at index 2 for type/field Post/body.


{ name: 'body',

type: 'bodyPortableText',
title: 'Body'



_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: {
// preference or highlighting by editors.
decorators: [
{ title: 'Strong', value: 'strong' },
{ title: 'Emphasis', value: 'em' },
{ title: 'Underline', value: 'underline' },
{ title: 'Strike', value: 'strike-through' }
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
I am using the Sanity blog starter template
user M
Aug 11, 2020, 4:36 PM
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
Aug 11, 2020, 5:19 PM
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 link
Aug 11, 2020, 5:21 PM
Ah I see, you‚Äôll have to ‚Äúhoist‚ÄĚ your
type field in
to 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'
And then include this as follows in `bodyPortableText`:

  type: 'myCode'
And add it to your
import myCode from './objects/myCode'
export default createSchema({
  types: schemaTypes.concat([
Aug 11, 2020, 6:53 PM
user M
Thank you so much ‚̧ԳŹ
Aug 11, 2020, 7:29 PM
I was looking for issues in an 'object' and completely missed out on the code component!!
Aug 11, 2020, 7:29 PM
Thanks a lot!
Aug 11, 2020, 7:29 PM
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.

Was this answer helpful?