#Field types
Fields define the data a model can store. Each field uses one field type, and the type you choose determines how content editors enter the value and how the API returns it. This page helps you choose the right field type and links to the guides for setting up each one.
For the GraphQL types each field returns, and example queries for every field type, see the Field types API Reference. For how editors work with each field in the content editor, see Field types in the content editor.
#Add a field to a model
- Open the model in the Schema builder.
- From the Add fields sidebar, select a field type.
- Configure the field display name, API ID, and any options or validations.
- Click Add.
You can add fields to custom models and to the system Asset model. Every model also includes system fields, which Hygraph manages automatically.
Avoid reserved terms when you set API IDs.
#Choose a field type
| Field type | What it stores | Typical use |
|---|---|---|
| Single line text | A string | Headings, page titles, email |
| Multi line text | A string with no formatting | Descriptions, raw text such as HTML or XML that you parse yourself |
| Markdown | A Markdown string | An alternative to Rich text, MDX |
| Slug | A URL-safe identifier | Page URLs, such as getting-started |
| Rich text | Formatted text, returned as raw, html, markdown, and text | Body copy with headings, links, tables, images, and lists |
| Integer | A whole number | Prices in cents, stock quantities |
| Float | A floating point number | Distance, weight, volume, ratings |
| Boolean | true, false, or null | On sale, part of a bundle, accepts comments |
| Date | An ISO 8601 date | Event dates |
| Date and time | An ISO 8601 date and time | Event start times |
| JSON | A JSON value | Large amounts of data from other systems |
| Color | A color as HEX, RGBA, and CSS values | Background or theme colors |
| Location | Latitude and longitude | Shop or venue locations |
| Asset | A connection to one or more assets | Images, PDFs, and other files |
| Enumeration | One value from a predefined list | Commodity type, status |
| Taxonomy | A node from a hierarchical list of terms | Product categories |
| Component | A reusable group of fields | Banners, page sections, blocks |
| Reference | A connection to entries in one or more models | Authors, related posts, categories |
| Remote field | Data fetched from a remote source | Product price and availability from an external API |
#Text fields
Single line text, Multi line text, Markdown, and Slug are all variants of the String type. They differ in how they appear to content editors, but the API queries all of them the same way and returns a string.
- Single line text: Use for short values such as headings, page titles, and email addresses.
- Multi line text: Use for text that needs no formatting, or for raw text such as HTML and XML where you control the parsing.
- Markdown: Use as an alternative to Rich text when you want to store Markdown, for example to use it with MDX.
- Slug: Use to generate a URL-safe, human-readable identifier for an entry. You can configure it to generate its value from a template built from other fields on the model, including fields on a related model. See Slug field.
#Rich text
Rich text stores formatted content and renders an editor with tools for headings, links, tables, images, and lists. The API returns it in four formats by default: raw, html, markdown, and text. A json format is also available when embeds are enabled.
When you add a Rich text field, you can enable embedding and select which models editors can embed in the field.
The embedding setting is permanent and cannot be edited after the initial save.
If you allow multiple values for a Rich text field, you cannot mark the field as required.
To work with Rich text in the API, see Rich text field.
#Numbers and booleans
- Integer: Use for whole numbers, such as prices in cents or stock quantities.
- Float: Use for fractional values that need precision, such as distance, weight, volume, or ratings.
- Boolean: Use for yes/no values, such as whether a product is on sale or a post accepts comments. Booleans default to
null, and can betrueorfalse.
#Dates
Both date field types follow the ISO 8601 standard.
- Date: Use when you only need the date. For example, September 22, 1989 is stored as
1989-09-22. - Date and time: Use when you also need the time, for example
1989-09-22T09:30:00+00:00.
#JSON
JSON stores a JSON (JavaScript Object Notation) value. Use it to store large amounts of data from other systems. Editors don't normally work with this field.
#Color
Color stores a color that the API can return as a HEX value, an RGBA value, or a CSS value. In the content editor, editors pick the color from a palette or enter a HEX or RGB code, and can set opacity.
#Location
Location stores a latitude and longitude. In the content editor, editors select the coordinates on a map. In the API, you can also query the distance in meters from a latitude and longitude that you provide.
#Assets
Assets can be any file type, not only images. Adding an asset field to a model connects that model to the system Asset model. Depending on the field configuration, editors can select one asset or several.
The Asset model comes with its own asset fields, and you can add your own fields to it. To learn how assets work, see Assets.
#Enumerations and taxonomies
Both field types let editors pick from a predefined list of values. You create the enumeration or taxonomy in the schema first, and then add a field that uses it to any model.
- Enumeration: A flat, predefined list of values. Editors select a value from a dropdown. See Enumerations.
- Taxonomy: A group of terms arranged in a hierarchy. Editors select a node from the hierarchy, and the API returns both the selected node and the full path to it. See Taxonomies.
If you allow multiple values for an enumeration or taxonomy field, you cannot mark the field as required.
#Components
A component is a reusable group of fields. You define the fields once, and editors fill them with different content each time the component is used in an entry. There are two component field types, and both support multiple values:
- Basic component field: Allows only one component type.
- Modular component field: Allows two or more component types. Editors choose which component to add.
The Studio UI shows up to 50 component instances per entry, and you can nest components up to 4 levels deep. See Components.
#References
References connect entries across models. When you add a reference field, you choose:
- Reference type: Whether the field references one model, or multiple models (Union Type).
- Reference direction: One-way, where the field is queryable only from the model you add it to, or two-way, where Hygraph adds a reverse field to the referenced model. Union Type references are always two-way.
- Relation cardinality: How many entries can be connected on each side, such as one to many or many to many.
Reference type, model to reference, reference direction, and relation cardinality cannot be changed after you save the field. To change them, delete and recreate the field.
See References to set up a reference field, and Components or references to decide which one fits your content.
#Remote fields
Remote fields fetch data from a remote source and connect it to an entry of the model. Each remote field is related to a single remote source and a single custom type. You must configure the remote source on your project before you can add a remote field.
- REST remote field: Sends a GET or POST request to a path you specify on a REST remote source.
- GraphQL remote field: Sends a GET or POST request to a GraphQL remote source, using the query entry point you select.
See Remote content to add a remote field, and Remote Fields vs Top-level Remote Fields to choose between them.
#Configure fields
After you choose a field type, you can configure how the field behaves. Not all options are available for all field types. Common options include:
- Allow multiple values: Returns an array to the API. You can only set this when you create the field.
- Localize field: Allows translations for each locale in your project.
- Make field required and Set field as unique: Validate entries before they can be saved.
- Field visibility: Controls whether editors can see or edit the field in the UI. Field visibility has no relation to permissions or security.
- Conditional visibility: Shows a field to editors only when they need it. See Conditional fields.
For every option, its constraints, and the matching Management SDK parameters, see Field configuration.
#Related docs
- Field types API Reference: GraphQL types and example queries for each field type.
- Field configuration: Settings, validations, and advanced options for fields.
- Field types in the content editor: How editors work with each field type.
- Models: Create and manage the models that fields belong to.