Field Types
Fields are the building blocks of your content models. When you create a model, you add fields to define what data each record can hold.
Overview
Foir recognizes a fixed set of built-in field types. Each field type has its own editor experience, validation rules, and configuration options. The string you store in a field’s type is the lowercase name of one of these types — anything else is rejected by the platform validator.
All fields support these common options:
| Option | Description |
|---|---|
| Label | Display name shown in the editor |
| Key | Unique identifier used in APIs (auto-generated from label) |
| Required | Must be filled before saving/publishing |
| Help Text | Guidance shown below the field in the editor |
| Default Value | Pre-filled value for new records |
| Queryable | Materialize the field for fast filtering/sorting (see Queryable fields) |
| Guarded | Which sides take the field’s own grant (see Guarded fields) |
The built-in field types
There are sixteen built-in field types:
| Type | Stores | Editor / widget |
|---|---|---|
text | A string (single- or multi-line) | Text input (or textarea via config.widget) |
integer | A whole number | Number input |
decimal | An exact decimal, carried as a string | Text input (numeric keypad) |
boolean | True/false | Checkbox |
date | A date or date-and-time | Date picker |
select | A reference to a record of another model | Record picker |
enum | A literal string token from inline options | Enum select |
json | Arbitrary JSON | JSON editor |
list | An ordered array of items | Array editor |
model | A model key (reference to a model schema) | Model picker |
reference | A reference to another record | Reference picker |
file | An uploaded file | File picker |
image | An uploaded image with metadata | Image picker |
video | An uploaded video with metadata | Video picker |
geopoint | A geographic point, { lat, lng } | Map picker |
prose | Translatable rich text, with models placed inline | Prose editor |
In addition, any model with inline mode enabled becomes usable as a field type by its own key. See Inline Schemas.
Text Fields
Text
A string field for titles, names, descriptions, and prose. By default it renders as a single-line input. To get a multi-line editor, set config.widget to textarea (see Widgets).
{
"key": "title",
"type": "text",
"label": "Title",
"required": true
}Multi-line:
{
"key": "excerpt",
"type": "text",
"label": "Excerpt",
"config": { "widget": "textarea" }
}Translatable: Yes, unless the field opts out.
A text field carries a value per locale without any setting. Set config.translatable to false on a field that holds a link, an anchor, a key or a slug:
{
"key": "href",
"type": "text",
"label": "Link URL",
"config": { "translatable": false }
}The field is then left out of translation: the translation report does not list it, a translation written to it is refused, and the editor edits its one value whichever locale is on screen. Only false opts out: a field with translatable absent or set to true is translatable.
Prose
Translatable rich text — headings, bold/italic, links, lists — and, where the field admits them, your own models placed inline among the paragraphs.
{
"key": "body",
"type": "prose",
"label": "Body"
}That declaration is text only. A prose field admits nothing but text unless it says otherwise, which is what makes the common case the short one.
To place models in the flow, list them:
{
"key": "body",
"type": "prose",
"label": "Body",
"config": {
"allowedTypes": ["cta", "editorial_media"]
}
}allowedTypes takes inline-mode model keys and the media primitives (image, video, file, reference, geopoint). Nothing outside the list can be placed, and a write carrying one is refused by key.
There is one more knob: config.passages: false turns the field into a pure arranger — models only, no typing. Use it for a section stack that should never contain loose paragraphs.
What a prose value is
A flow: { v, entries }. Each entry is either a passage (a paragraph, heading, quote or list item) or an embed (one of the models allowedTypes admits). Every entry carries an _id, minted once and never changed, so a translation or a comment anchored to a paragraph stays anchored.
Prose nests without limit. A model placed in a flow may itself have a prose field, and that flow validates in full — the modelling bounds how deep a document goes, not the format.
Reading it
A prose field resolves to a wrapper with four members:
query {
page(naturalKey: "home") {
body {
html
markdown
json
entries {
__typename
... on Passage {
_id
kind
token
align
list
level
spans { text marks }
markDefs
}
... on Cta { label href }
... on EditorialMedia { image { url alt } }
}
}
}
}entriesis the typed reading, and the one that keeps prose structured.Passageis a first-class member alongside your own models.htmlandmarkdownare the passages only. An embed is omitted from both by declaration — the platform will not invent markup for your model, because whatever it invented would be wrong for someone. A renderer that wants the embeds readsentries.jsonis the flow verbatim: the lossless escape hatch, where an entry nothing recognises still survives a round trip.
A fragment must select __typename explicitly. Codegen types the discriminant, but the HTTP response carries only what the document asks for — a renderer switching on __typename without it falls through every case silently.
The same read through the data client:
const page = await foir.page.findUnique({ naturalKey: 'home' });
for (const entry of page.body?.entries ?? []) {
if (entry?.__typename === 'Passage') renderPassage(entry);
else renderEmbed(entry);
}Inside a passage
A passage is a flat record, not a tree:
| Member | What it carries |
|---|---|
_id | The entry’s identity, minted once and never changed. 4 to 64 characters, starting with a lowercase letter, lowercase letters and digits only, unique within the flow |
_type | "passage" for text, or the placed model’s own key for an embed |
kind | paragraph, h1 through h6, quote, code. This is the whole set; anything else is refused |
token | A design-token override; beats kind when set |
align | Text alignment |
list / level | List type and nesting depth, flat rather than nested. Both or neither |
language | The code language. Only valid on kind: "code" |
spans | Runs of { text, marks } — marks are named (bold, italic, code, …) or the _id of one of its markDefs |
markDefs | Data for the marks that need it — links, today |
These nine are the whole member set. Anything else in a passage is refused.
A soft break is a \n inside a span’s text, not a separate entry.
Writing it
The value you send is the flow itself. There is no wrapper and no partial form: send the whole { v, entries } envelope, exactly this shape and nothing else.
{
"v": 1,
"entries": [
{
"_id": "intro01",
"_type": "passage",
"kind": "paragraph",
"spans": [
{ "text": "Rewax twice a year, ", "marks": [] },
{ "text": "see the guide", "marks": ["care01"] }
],
"markDefs": [{ "_id": "care01", "type": "link", "href": "/care" }]
},
{
"_id": "care02",
"_type": "passage",
"kind": "h2",
"spans": [{ "text": "Care", "marks": [] }]
}
]
}v must be 1. Any other value is refused rather than guessed at, which is what lets the format change later without anyone sniffing at what is already stored.
Every entry needs a _type. It is "passage" for text. For an embed it is the placed model’s own key, and that key must be one config.allowedTypes admits.
_id is 4 to 64 characters, starts with a lowercase letter, and carries only lowercase letters and digits. No uppercase, no hyphens, no underscores. Ids are unique within a flow, and markDef ids are unique within their passage. Leave it out on a new entry and the platform mints one; once an entry has one, send it back unchanged: a translation or a comment anchored to a passage is anchored to its _id. A markDef needs its _id from the start, because the span marks that use it name it.
kind is a closed set: paragraph, h1, h2, h3, h4, h5, h6, quote, code. There is no heading.
The eight decorations are bold, italic, underline, strikethrough, code, subscript, superscript and highlight. Any other value in marks must be the _id of a markDef on the same passage, or the write is refused.
Three rules that catch people out:
listandleveltravel together. Both or neither, withlevelan integer from 1 to 6. Depth is this number, not a nested structure.languageis only valid onkind: "code".- Adjacent spans may not carry identical mark sets. Merge them. Without that rule the same text has unboundedly many representations and nothing can be compared.
Omit optional members rather than sending them empty. No null, and no empty markDefs.
A refusal names the _id of the entry it objects to, so a long document tells you where to look rather than only that something is wrong.
Translatable: Yes, unless the field opts out. A prose field takes config: { "translatable": false } as a text field does, and is then left out of translation. Variants apply per entry as well as per field. See Variants.
richtext and flexible
Both are retired into prose. The schema builder no longer offers either, and existing values were converted in place. A model declaring either, as a field’s type or as a list’s item type, is refused with a message telling you to use prose.
Widgets
Each field type has a default editor widget and, for some types, a small set of allowed alternatives. Override the widget with config.widget. The most common case is rendering a text field as a multi-line textarea:
{ "key": "summary", "type": "text", "config": { "widget": "textarea" } }text also allows color, select and radio widgets, and date allows datetime-picker.
Media Fields
Image
Upload and manage images with built-in metadata support. Resolves to an object with url, width, height, alt, blurhash, dominantColor, mimeType, fileSize, focalPoint, crop, variants, webp and avif.
alt is null on a record’s image today. The alt text set on a file reaches the file library and the files query, not a record that uses the image. To publish alt text with an image, add a text field beside the image field (translatable, like any text) and read the two together.
The GraphQL type is called Image, not ImageValue. A ... on ImageValue fragment is a validation error, not an empty result.
Two things it does not do:
- It carries no
id. The file id written into the field cannot be read back through the image value — if you need the id, keep it yourself at write time. includecannot reach it.includeaddresses relations, and an image is a value on the record rather than a related record, so it is expanded whole on every read that selects the field.omitis the lever for a read that does not render it.
{
"key": "featuredImage",
"type": "image",
"label": "Featured Image"
}Features:
- Alt text — Text for accessibility
- Focal point — Set the important area for smart cropping
- Crops — Per-usage crop geometry
- Blurhash — Automatically generated placeholder hash
- Variants: pre-tokenised size presets (
thumbnail,small,medium,large,xlarge,_2xl,_3xl,_4xl), with the same set in WebP and AVIF underwebpandavif
Translatable: No. Put translated alt text in a text field beside the image.
Video
Upload videos with automatic processing. Resolves to a Video object (not VideoValue) with url, thumbnailUrl, previewUrl, hlsManifestUrl, width, height, duration, blurhash, dominantColor, mimeType, and fileSize.
{
"key": "heroVideo",
"type": "video",
"label": "Hero Video"
}Features:
- Poster image — Thumbnail shown before playback
- HLS streaming — Automatic manifest generation
- Duration — Automatically detected on upload
Translatable: No
File
Any file type — PDFs, documents, spreadsheets, downloads. Resolves to a FileValue object with url, filename, mimeType, and size.
{
"key": "attachment",
"type": "file",
"label": "Attachment"
}Translatable: No
Numeric, Date, and Boolean Fields
There is no number. A number that counts money and a number that counts items
are not the same type, and the platform will not guess which you meant.
Integer
Whole numbers: counts, quantities, seats, display order, years.
{
"key": "quantity",
"type": "integer",
"label": "Quantity",
"required": true
}An integer travels as a JSON number. Values beyond ±2^53 are refused rather
than truncated — past that point a double cannot tell one integer from its
neighbour, and a value that large is an identifier rather than a quantity. Store
it as text, which is what Twitter’s id_str and Stripe’s string ids do.
Translatable: No
Decimal
Exact fractional values: money, rates, percentages, weights, measurements.
{
"key": "price",
"type": "decimal",
"label": "Price",
"required": true
}A decimal is a string on the wire, and that is the point. Record data
crosses the API as JSON, whose only numeric representation is an IEEE-754
double, and base 2 cannot represent 0.1: the nearest double is
0.1000000000000000055511151231257827021181583404541015625. That is not an
imprecise version of the value, it is an exact representation of a different
one. A thousand line items at 0.10 sum to 99.9999999999986, and
(0.1 + 0.2) + 0.3 and 0.1 + (0.2 + 0.3) disagree by a penny.
Sending a JSON number to a decimal field is refused rather than converted, because by the time it arrives the digits the author typed are already gone.
The string is the wire format, not what you hold in code. @foir/sdk/data
returns a FoirDecimal with exact arithmetic — add, sub, mul, toFixed,
cmp — and foir types generates that type, so a + b on two prices is a
compile error rather than the string concatenation "19.99" + "2.00" would
otherwise give you.
The data client makes that conversion for every decimal field of every record a
call returns, inside composites, block members and included relations too,
because the module foir types writes says which fields are decimals. A value
it does not hand you, such as one you parse from a raw GraphQL response or read
back from a cache that stored JSON, is still the string: pass it to decimal().
Scale is preserved: 19.90 stays 19.90 and is not reduced to 19.9. What the
author typed is what the field serves. Comparison is numeric everywhere in the
platform, so the two still match each other in a filter.
Translatable: No
Date
Date picker for publish dates, event dates, deadlines, and scheduling. Use the datetime-picker widget for date-and-time.
{
"key": "publishDate",
"type": "date",
"label": "Publish Date"
}Translatable: No
Boolean
Yes/no toggle for featured flags, visibility settings, and switches.
{
"key": "isFeatured",
"type": "boolean",
"label": "Featured"
}Translatable: No
Selection Fields
Select (record-backed)
Choose a value from the records of another model. select resolves through the dataloader to the referenced record — it is not an inline list of options. Configure it with optionModelKey (the model whose records are the choices) and, optionally, multiple for multi-select.
{
"key": "language",
"type": "select",
"label": "Language",
"config": {
"optionModelKey": "language",
"multiple": false
}
}Set multiple: true to allow multiple selections (stored as an array).
Translatable: No
Enum (inline options)
Choose from a fixed, inline list of { label, value } options. Unlike select, enum values are literal string tokens stored directly on the record, and there is no related model. The storefront receives a typed string-literal union of the values exactly as declared: a value is the GraphQL enum value the data API speaks, so it must be a valid GraphQL name (see defineEnumField).
{
"key": "category",
"type": "enum",
"label": "Category",
"config": {
"options": [
{ "label": "News", "value": "news" },
{ "label": "Tutorial", "value": "tutorial" },
{ "label": "Case Study", "value": "caseStudy" }
],
"multiple": false,
"default": "news"
}
}Set multiple: true for a multi-select that stores an array of tokens.
Translatable: No
Reference and Model Fields
Reference
Link to another record. Use for authors, related posts, parent pages, and any content relationship.
{
"key": "author",
"type": "reference",
"label": "Author",
"config": {
"referenceTypes": ["team-member"]
}
}Config options: referenceTypes (array of model keys the field can link to)
Translatable: No
Model
Store a reference to a model schema (the model’s key), rather than a record. Useful for configuration that needs to point at a model type.
{
"key": "targetModel",
"type": "model",
"label": "Target Model"
}Translatable: No
Structured Data Fields
JSON
Arbitrary JSON data for complex or unstructured values.
{
"key": "metadata",
"type": "json",
"label": "Metadata"
}Translatable: No
List
Array of items for ordered collections.
{
"key": "bulletPoints",
"type": "list",
"label": "Bullet Points"
}Translatable: No
Queryable fields
By default, only the always-available direct columns (id, naturalKey, createdAt, etc.) and a small set of indexed fields are fast to filter and sort on. To filter or sort on a declared field, set queryable: true. The platform materializes the field into its index and rebuilds the index over existing records when the change is published. Until then, filters keep serving the fields the published model makes queryable.
{
"key": "status",
"type": "enum",
"label": "Status",
"queryable": true,
"config": { "options": [ ... ] }
}Flip queryable on text, integer, decimal, date, and boolean fields that show up in frequent filters or sorts. See Records → Filtering.
Guarded fields
A field follows its model unless a side of it is guarded. A guarded side is read, or written, only by a holder of the grant that names the field, records:read:<model>.<field> or records:write:<model>.<field>, at a reach that covers the record. A grant on the model doesn’t reach it. The platform enforces the write side on every record write path. See Guarded fields for who to give the grants to.
{
"key": "internalNotes",
"type": "text",
"label": "Internal Notes",
"guarded": { "read": true, "write": true }
}Translatable Fields Summary
Text and prose fields carry per-locale translations. They are translatable without any setting, and a single field opts out with config.translatable: false:
| Field Type | Translatable |
|---|---|
| Text | Yes, unless the field sets config.translatable: false |
| Integer | No |
| Decimal | No |
| Boolean | No |
| Date | No |
| Select | No |
| Enum | No |
| JSON | No |
| List | No |
| Model | No |
| Reference | No |
| File | No |
| Image | No |
| Video | No |
| Geopoint | No |
| Prose | Yes, unless the field sets config.translatable: false. Variant overrides apply per record, per field and per entry |
See Localization for details on how translations work.
In the console
Adding fields to a model
- Go to Models
- Select or create a model
- Click Add Field
- Choose the field type
- Configure options (label, required, help text, widget, type-specific settings)
- Save the model
Custom field types
You can create your own composite field types by defining a model with inline mode enabled. For example, create a “Button” model with text, URL, and style fields, then use it as a field type on any model.
See Inline Schemas for details.
Best Practices
- Mark fields as required only when truly necessary. Optional fields give content teams more flexibility.
- Use help text to guide editors on format expectations, character limits, or content guidelines.
- Choose the most specific field type for the data. Use
decimalfor prices (nottext, and notinteger— the first thing to cost £4.99 has no way back),integerfor counts,datefor dates, andbooleanfor toggles. - Use
enumfor a fixed small set of tokens; useselectwhen the choices are themselves records you manage in another model. - Set
queryable: trueon any field you need to filter or sort by on the API. - Translations need no enabling: every
textandprosefield is translatable. Setconfig.translatable: falseon the ones that hold a link, an anchor, a key or a slug, so a translator is never offered them. - Use references instead of duplicating content. Link to a shared “Author” record rather than entering the author name on every post.