Is it Possible to Make a Schema Field Required?

5 replies
Last updated: May 12, 2020
Is it possible to make a schema field required? I have added
required: true
to a few fields but an API mutation seems to still pass through even when no values.
May 12, 2020, 11:34 AM
Normally, you would set validation according to the information in the document Jørn shared above. However, it’s noteworthy that validation is only done client-side within the Studio at this point. That means any API mutations are not validated according to the same rule and you would have to take care of validation yourself here. In the future it might be extended to work server-side as well.
May 12, 2020, 12:15 PM
Good point, Peter
May 12, 2020, 12:15 PM
OK thanks for the info!
May 12, 2020, 12:26 PM
That's a shame that would be a great addition! I'm not sure what percentage of your users work mainly in the studio and who are using mainly as an api?
May 12, 2020, 12:28 PM

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.

Was this answer helpful?