👋 Next.js Conf 2024: Come build, party, run, and connect with us! See all events

Error when adding custom object to block content annotations in Sanity V3

1 replies
Last updated: Sep 26, 2022
Hello!I’m editing the annotations in the block content to support external links and other custom objects in the new V3.
Since I’m using GraphQL, I can’t have any inline objects and all objects need to be defined globally. So I created a type externalLink as:


export default {
  name: 'externalLink',
  title: 'External Link',
  type: 'object',
  liveEdit: false, 
  fields: [
    {
      title: 'URL',
      name: 'href',
      type: 'url',
    },
  ]
}
I added this type to the schema. but when I want to place it in the annotations of my block Content, I get the following error:


Error: Could not resolve jsonType of undefined. No parent type found
Error: Could not resolve jsonType of undefined. No parent type found
    at isJSONTypeOf (<http://localhost:3333/node_modules/.vite/deps/chunk-TA2UENNL.js?v=47494152:83241:11>)
    at <http://localhost:3333/node_modules/.vite/deps/chunk-TA2UENNL.js?v=47494152:83366:24>
    at Array.map (<anonymous>)
    at validateAnnotations (<http://localhost:3333/node_modules/.vite/deps/chunk-TA2UENNL.js?v=47494152:83357:22>)
    at validateMarks (<http://localhost:3333/node_modules/.vite/deps/chunk-TA2UENNL.js?v=47494152:83306:19>)
    at validateBlockType (<http://localhost:3333/node_modules/.vite/deps/chunk-TA2UENNL.js?v=47494152:83271:13>)
    at visitors.reduce._problems (<http://localhost:3333/node_modules/.vite/deps/chunk-TA2UENNL.js?v=47494152:83585:19>)
    at Array.reduce (<anonymous>)
    at <http://localhost:3333/node_modules/.vite/deps/chunk-TA2UENNL.js?v=47494152:83584:21>
    at <http://localhost:3333/node_modules/.vite/deps/chunk-TA2UENNL.js?v=47494152:83599:40>

And this is my BlockEditor code:

export default {
  title: 'Block Editor',
  name: 'blockEditor',
  type: 'array',
  of: [
    {
      title: 'Block',
      type: 'block',
      styles: [
        {title: 'Normal', value: 'normal'},
        {title: 'H2', value: 'h2'},
        {title: 'H3', value: 'h3'},
        {title: 'Quote', value: 'blockquote'},
      ],
      lists: [{title: 'Bullet', value: 'bullet'}],
      marks: {
        decorators: [
          {title: 'Strong', value: 'strong'},
          {title: 'Emphasis', value: 'em'},
        ],
        annotations: [
          {
            type: 'externalLink'
          }
        ],
      },
    },
    {
      type: 'image',
      name: 'image',
      options: {
        hotspot: true,
      }
    },
    {
      name: 'line',
      title: 'Line',
      type: 'line',
    },
  ],
}

This example shows me that it is possible (in V2), so my question is, what am I doing wrong here?
[I’m using version 3.0.1-dev-preview.0]
Sep 26, 2022, 5:07 AM
Hey
user M
! We're handling V3 support on Github Discussions .
Sep 26, 2022, 5:17 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?