Content type schema as code

by Peter Balazs on 05/02/2018

In a CMS it is a must for editors to have full control over the content. To be able to create drafts, publish immediately or schedule for a given time, to be able to check the version history, rollback to a previous version if necessary. If they have these controls, why can’t developers have similar?

For developers, the essential part of cloud CMS is the content model. We think they should have full control over it, and not just store in a black box. And this is why from the very first minute when we started building Mozaik, we knew we were going to give full write access to the developers. To be able to manage not only the content programmatically but the content model as well. Because as a developer you should be able to source-control your schema, create reusable templates for yourself and set up a new project based on those templates in no time.

Creating content types through the API

To create content types and fields you can use the createContentType and createField mutations. You can find a full example on Github.

Currently, you can't import a full schema in one call, but you have to create the content types first, and then add the fields to each of them. The reason is there can be dependencies between content types when you use them as types for other fields.

Next steps

We think being able to manage your content type schema programmatically is a mandatory feature in a CMS, but we don’t want to stop here. We're aware that calling the API multiple times to create a simple template might not be the ideal set up and we're planning to add an importSchema mutation as a next step. With this new mutation, you will be able to define your schema as you would define a GraphQL schema with the GraphQL Schema Definition Language.

On a bit longer term we will support content type schema migration to enable you to manage schema changes between development, staging, and production environment painlessly.