Anonymous inline object error in image array for graphql deploy
The issue is that GraphQL requires all object types to have explicit names, and you're using an inline anonymous object inside your array definition. Even though you've defined imageArray as a named type, the image object inside the of array is anonymous because you're adding custom fields to it inline.
Here's how to fix it - you need to extract the image object into its own named type:
Create a new file imageWithMetadata.js (or similar):
export default {
name: 'imageWithMetadata',
type: 'image',
title: 'Image with Metadata',
options: {
metadata: ['lqip', 'palette']
},
fields: [
{
title: 'Caption',
name: 'caption',
type: 'string',
options: {
isHighlighted: true
}
},
{
title: 'Alternative text',
name: 'alt',
type: 'string',
options: {
isHighlighted: true
}
}
]
}Then update your imageArray.js to reference this named type:
export default {
name: 'imageArray',
type: 'array',
title: 'More Images',
of: [
{
type: 'imageWithMetadata'
}
]
}Don't forget to add the new type to your schema:
Make sure you import and include imageWithMetadata in your schema configuration where you define all your types.
The key principle here is explained in the Sanity documentation on lifting anonymous object types: GraphQL (and other features like copy/paste) require all object types to have explicit names. Whenever you're adding custom fields to a built-in type like image, you need to define it as a separate named schema type rather than inline.
Show original thread8 replies
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.