Data validations

Grafbase improves data validation by providing custom scalars and schema directives.

By default all of the scalars validate the data you send to each field is of the correct type.

You can also validate the actual data values with custom directives that should be used inside of your Grafbase schema.

The @unique directive tells Grafbase that this value must be unique (and case-sensitive) within the collection.

type User @model {
  email: String! @unique
}

The @length directive enables specifying a minimum or a maximum (or both) value for a field.

The following example rejects mutations for Post objects with a title field value less than 10 characters or more than 255 characters, or more than five tags values:

type Post @model {
  title: String @length(min: 10, max: 255)
  tags: [String] @length(max: 5)
}
Was this page helpful?