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

Reference type has a invalid value for property "to"

All reference types must define what type of documents they may refer to. The "to" property must be an array of objects that describes the type of a valid reference. Each entry in to, must have a type-property which must be the name of a valid schema type.

{
  type: 'reference',
  name: 'references',
to: [ // The "to"-property must be set, and it must be an array of at least one type
{
type: 'author', // type is required
title: 'Author' }, { type: 'book', title: 'Book' } ] }

To-types must be unique, or named

In order to know which type description a reference value belongs to, you can not add multiple entries to of with the same type, unless you also give them a name to tell them apart. This is therefore not allowed:

{
  type: 'reference',
  name: 'authorReference',
  to: [
    {
      type: 'author',
      title: 'Author'
    },
    {
      type: 'author', // 💥 ERROR will not be able to tell reference values apart
      title: 'Another author'
    }
  ]
}

Instead, you can name the reference type. This will work:

{
  type: 'reference',
  name: 'authorReference',
  to: [
    {
      type: 'author',
      title: 'Author'
    },
    {
      type: 'author',
name: 'anotherAuthorReference', // all good
title: 'Another author' } ] }

The value of this definition will have its _type set to either author or anotherAuthor, depending on which of the type were selected when the value was set e.g.:

{"_type": "reference", "_ref": "329e893ewi"}

Or:

{"_type": "anotherAuthorReference", "_ref": "293e90iok3elwq213er"}

Was this article helpful?