Error when adding custom object to block content annotations in Sanity V3
Looking at this error with your Sanity v3 Studio configuration, the issue is that when you're using GraphQL with Portable Text, you need to define annotation types globally rather than inline within the block configuration.
The error "Could not resolve jsonType of undefined. No parent type found" occurs because the schema compiler can't properly resolve the inline object type definition when it's nested directly in the annotations array.
Here's how to fix it:
Step 1: Define your externalLink as a separate schema type
Keep your externalLink type definition in a separate file:
// schemas/externalLink.ts
export default {
name: 'externalLink',
title: 'External Link',
type: 'object',
fields: [
{
title: 'URL',
name: 'href',
type: 'url',
},
]
}Step 2: Reference it properly in your block configuration
In your blockEditor schema, reference the type by name only:
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: [
{
name: 'externalLink',
type: 'externalLink' // Just reference the type name
}
],
},
},
// ... other block types
],
}Step 3: Make sure both types are registered in your schema
In your sanity.config.ts or schema configuration:
import externalLink from './schemas/externalLink'
import blockEditor from './schemas/blockEditor'
export default defineConfig({
// ... other config
schema: {
types: [
externalLink, // Register it globally first
blockEditor,
// ... other types
],
},
})The key difference from v2 is that v3 requires stricter type resolution, especially when using GraphQL. By defining the annotation type globally and then referencing it by name (rather than defining it inline), the schema compiler can properly resolve the type hierarchy.
This approach also has the benefit of making the type reusable across multiple block configurations if needed, and it ensures GraphQL can properly generate types for your schema. As noted in the Portable Text Editor configuration docs, when using GraphQL with Sanity, you should hoist annotation types as separate schema types rather than using anonymous inline definitions.
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.