Creating a top-level schema for nested objects in GraphQL
Hey! This is a common issue when using GraphQL with Sanity. The error you're seeing happens because GraphQL requires all object types to be explicitly named at the top level of your schema, but fieldset groups in Sanity are just organizational helpers for the Studio UI - they don't create actual schema types.
The good news is that groups/fieldsets are purely for Studio organization and don't affect your actual data structure. You don't need to create a schema type for the groups themselves.
Here's what's likely happening: you probably have an anonymous inline object somewhere in your schema (not the group itself, but an actual field). GraphQL can't handle anonymous objects - they need to be "lifted" to named, top-level object types.
How to fix it:
- Find the anonymous object - Look for fields in your schema that look like this:
{
name: 'myField',
type: 'object', // Anonymous inline object
fields: [
// nested fields here
]
}- Create a named object type - Move this to a top-level schema definition:
// schemas/myFieldObject.js
export default {
name: 'myFieldObject', // Give it a unique name
type: 'object',
fields: [
// your nested fields here
]
}- Reference it in your original schema:
{
name: 'myField',
type: 'myFieldObject' // Reference the named type
}- Deploy your GraphQL API again:
sanity graphql deployThe Object Types documentation explains this in detail, and there's a helpful answer specifically about this GraphQL error that shows more examples.
Important: Your fieldset or group configuration for organizing fields in tabs stays exactly as it is - you don't need to change that at all. This is purely about converting any inline object type definitions to named types.
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.