Joint session with Vercel: How to build intelligent storefronts (May 15th)

How to create self-referencing schemas in Sanity without circular references?

2 repliesLast updated: Nov 29, 2025

Does anyone know how you reference a schema from a schema? (i.e. self-referencing).
If a section can have children and one type of child can again be a [nested] section, how do you do that in the schema without creating a circular reference? Is this the right way?


export default defineType({
  name: "section",
  title: "Section",
  type: "object",
  fields: [

    defineField({
      type: "array",
      name: "blocks",
      title: "Content",
      of: [

        defineArrayMember(codeBlock), // <-- You can't do this with section because of circular reference
        
        defineArrayMember({ // <-- SO is this what you're supposed to do?
          name: "section",
          title: "Section",
          type: "section",
        }),

      ],
    }),

  ],

});
AI Update

Yes, exactly! The approach you're showing in your second example is the correct way to handle self-referencing schemas in Sanity. You reference the schema type by its name as a string.

Your code is spot-on:

defineArrayMember({
  name: "section",
  title: "Section",
  type: "section", // <-- This string reference prevents circular dependency issues
})

This works because Sanity's schema system resolves type references by name at runtime, not at definition time. When you use type: "section" as a string, you're telling Sanity "look up the type named 'section' when you need it" rather than trying to import and nest the actual schema object directly.

Why this works

The key difference is:

This pattern works for any self-referencing or mutually-referencing schemas. You can have deeply nested structures like sections within sections within sections, and Sanity will handle it gracefully.

Additional tips

This is a common pattern for building flexible, nested content structures like navigation menus, nested comments, organizational hierarchies, or in your case, nested sections with blocks. The array fields documentation covers more about how arrays work with multiple member types, which applies to recursive structures as well.

Show original thread
2 replies

Was this answer helpful?

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.

Related contributions