Working with Fields

What are Fields?

Fields are a predefined type of content that provides structure for multiple content entries. For more, visit the Fields Concepts Documentation.

Setting up a Field

To create a field, you'll need a model first. Then from the fields tab on the left-hand side of the Schema view, drag out any field you'd like to use.

You will be prompted to create the name of this field, which will also auto-propagate the API ID.

In the Dropdown labeled Advanced, you will find toggles to allow or disallow:

  • Multiple values
  • Make a Field Required
  • Make Field Unique
  • Localize Field
  • Hide Field

Editing Fields

You can easily edit a field by hovering over it and then selecting "Edit Field". In the now opening modal, you are also able to click up the Advanced flag to set a field as required, unique or allow multiple values.

Edit Field

Primary Fields

Primary Fields can be used to select which field of a model should be shown in a Relational View. The default Primary Field is always the ID field. So when you are now connecting relations in the Content View, it will look like this:

Relational View with ID as Primary

In this particular case, I won't be able to tell which author this is.

To now change the primary field, I can head back to the schema view and hover over a field. The "Set Primary" button will be greyed out if the field itself is not set to be Required. To change this please refer to the Editing Fields section.

Set Primary Field

Now if we head back to the content view, we will see that the field we now selected to be primary will be shown when connecting authors.

Relational View with Text Field as Primary

Deleting Fields

You can delete a field by hover over the entry in your model. A "Delete Field" button will appear, click on that and then confirm by clicking the second prompt.

"Delete Fields"

Hidden Fields

Hidden fields are just about exactly the way they sound. They are fields that you can define as hidden from the UI at the point of defining the schema. Along with setting a field as required, unique, repeatable, translatable and more, you can also define a field as hidden.

Hidden Fields

The field will always be available through the generated API as that is a core tenant of the GraphQL specification, but there are many cases where it is helpful to simply hide the value from the user interface.

Two common cases for hidden fields are:

  • You want to create a relation but only want the relation visible from one model.
  • You have a field that will be altered programmatically from the API and don't want editors to see it.

But, as with all features built into GraphCMS, we provide you the tools and how you want to use them is up to you!

How does a Field translate to code?

Each field is its own type of content. For example, Single Line Text will output as a string, whereas Rich Text will output either raw, text, html, or markdown depending on the query. You'll want to have existing knowledge on how to use or (in instances like markdown) parse these content types. Each front end technology will do them slightly different.