Discussion on the benefits of code-based schemas in Sanity and potential for future UI tooling

9 replies
Last updated: Apr 9, 2021
I haven't used Sanity in about a year, so I set up a new project. Maybe I'm getting Sanity confused with a different product. Is there no interface to build out the content model? Is it all done programmatically?
Mar 20, 2021, 7:56 PM
yep, all done programmatically. That's actually the reason I love Sanity 😋git conflicts are a nightmare to solve when using UI that generates content model.
But there's a community plugin that allows to define the schema through a model. But I can't find it.
Mar 21, 2021, 8:33 AM
I'm also much faster writing the schema manually, especially when using snippets: https://marketplace.visualstudio.com/items?itemName=hdoro.sanity-snippets
Mar 21, 2021, 8:35 AM
I finished a sanity project last week and gone back to strapi to recreate it for a learning exercise and I too like the schema being code based.
Mar 21, 2021, 10:46 AM
Thanks for the feedback. I wasn't sure if I was missing something. Programmatically setting up the content model definitely has its advantages over using a UI. It's much faster, easier to share, etc. You don't have to follow a breadcrumb trail. But, there's times when I could use that visual representation or hand holding.
Mar 21, 2021, 1:28 PM
Scott, you may find
user S
’s schema generator UI concept useful. Also, if you have data you'd like to extract a schema from, my small generator tool may come in handy. And, especially,
user B
’s schema-inspector is a great plugin for getting "that visual representation or hand holding" you're looking for.
Overall, I'd say the Sanity team opted for code-based schemas first not only because they're easier to get right and be productive, but mainly because they're more capable - take a look at
custom validation patterns and you'll see you can do all sorts of fun stuff with them.
Eventually, as the ecosystem matures and people find UIs more and more useful for generating schemas, we'll definitely get some tooling to generate and inspect them visually, though
Mar 30, 2021, 4:46 PM
Creating that Schema generator taught me why programmatic is better 😅 the possibilities Sanity schema give you are almost more than you could model in a UI (well not without an extreme amount of work)
Mar 30, 2021, 4:50 PM
And it also allows for novel styles to flourish. Simeon's quick fields and Rupert Dunk's sanity-schema-builder are a great example of that: https://twitter.com/hdorodev/status/1376942258243657734
Excited about the approaches that will appear in the long term!
Mar 30, 2021, 5:05 PM
Thanks a bunch
user B
Mar 30, 2021, 11:32 PM
To follow-up on this: Knut also shared other benefits to code-based schemas in Twitter
Apr 9, 2021, 11:24 AM

Sanity– build remarkable experiences at scale

The Sanity Composable Content Cloud is the headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?