Boolean
Schema type reference for expressing truthy values.
A boolean, true or false.

Properties
Requiredtype
Value must be set to
boolean.
Requiredname
Required. The field name. This will be the key in the data record.
title
Human readable label for the field.
If set to
true, this field will be hidden in the studio. You can also return a callback function to use it as a conditional field.
readOnly
If set to
true, this field will not be editable in the content studio. You can also return a callback function to use it as a conditional field.
description
Short description to editors how the field is to be used.
initialValue
The initial value used when creating new values from this type. Can be either a literal value or a resolver function that returns either a literal value or a promise resolving to the initial value.
components
Lets you provide custom components to override the studio defaults in various contexts. The components available are
field,input,item,preview.
deprecated
Marks a field or document type as deprecated in the studio interface and displays a user-defined message defined by the single required
reasonproperty.If you deploy a GraphQL API schema, this property will translated into the
@deprecateddirective.
Options
layout
Either
switch(default) orcheckboxThis lets you control the visual appearance of the input. By default the input for boolean fields will display as a switch, but you can also make it appear as a checkbox.
Validation
required()
Ensures that this field exists.
custom(fn)
Creates a custom validation rule.
Input
{
title: 'Has the movie been released?',
name: 'released',
type: 'boolean'
}Response
{
"_type": "movie",
"released": true,
...
}New documents are created without schema-defined fields. This means that a boolean field in your schema will not immediately result in documents containing the boolean key. The key must be assigned a value for it to appear in a document. Make sure your front-end code treats a missing boolean value as false.
Protip
In GROQ you can handle missing booleans and false values equally like this *[_type == 'story' && featured != true] which would match stories where featured is false or missing (or to be fair, any other value that is not true).
Was this page helpful?