Custom objects and attributes
Read custom attribute values, custom object types and records, and smart collections with the FrontStage API
Custom attributes add fields to built-in content types. Custom objects are content types that a site defines. Both return their values as fields.
Read custom attributes
Every content type has customAttributes, a list of fields:
query EventAttributes($slug: String!) {
event(slug: $slug) {
title
customAttributes {
__typename
key
label
type
... on TextField { value }
... on NumberField { number }
... on BooleanField { boolean }
... on SelectField { values options { label value } }
... on DateField { value }
... on RichTextField { richText { html } }
... on ReferenceField {
references {
__typename
... on Person { name path }
... on Work { title path }
... on CustomObject { type title }
}
}
}
}
}With the variables {"slug": "season-2027-opening-gala"}, part of the response is:
[
{ "__typename": "TextField", "key": "age_rating", "label": "Age rating", "type": "text", "value": "All ages" },
{ "__typename": "NumberField", "key": "running_time", "label": "Running time (minutes)", "type": "number", "number": 110 },
{
"__typename": "ReferenceField",
"key": "featured_soloist",
"label": "Featured soloist",
"type": "relationship",
"references": [{ "__typename": "Person", "name": "Mina Okafor", "path": "/people/mina-okafor" }]
}
]To read one attribute, use customAttribute(key:):
query RunningTime($slug: String!) {
event(slug: $slug) {
runningTime: customAttribute(key: "running_time") {
... on NumberField { number }
}
}
}label and the options of a select field come from the attribute definition. attributes returns the same values as one JSON object under custom, in the shape the REST API and Liquid templates use. References in attributes are IDs only.
List custom object types
customObjectDefinitions returns the custom object types that are exposed in the public API, with their fields:
{
customObjectDefinitions {
handle
label
description
fields {
key
label
type
hasMany
}
}
}A type that is not exposed in the public API does not appear, and its records are not available.
Read custom object records
customObjects lists the records of one type by its handle:
query Faqs {
customObjects(type: "faq", limit: 50) {
totalDocs
docs {
id
title
question: field(key: "question") { ... on TextField { value } }
answer: field(key: "answer") { ... on RichTextField { richText { html } } }
}
}
}| Argument | Description |
|---|---|
type | The handle of the custom object type. Required. |
search | Records whose title contains this text. |
sort | title (default), -title, createdAt, or -createdAt. |
page, limit | Page number and page size. Default 20, maximum 100. |
An unknown handle returns an empty list. customObject(id:) returns one record.
A CustomObject has:
| Field | Description |
|---|---|
id, title | The record ID and title. |
type | The handle of its type. |
definition | The type, as CustomObjectDefinition. |
fields, field(key) | The values as fields. References return the linked records. |
data | The values as one JSON object, the shape Liquid templates read. Rich text appears as <key>_html. References are IDs. |
Follow references to custom objects
A block setting or a custom attribute can link to custom object records. A ReferenceField returns them as CustomObject items:
query FeatureCards {
page(path: "/") {
blocks {
... on ThemeBlock {
type
fields {
... on ListField {
items {
fields {
... on ReferenceField {
references {
... on CustomObject {
title
body: field(key: "body") { ... on RichTextField { richText { html } } }
}
}
}
}
}
}
}
}
}
}
}Smart collections
A smart collection is a list of records that an editor curates or defines with rules. Read it by slug or ID, and page through its items:
query FeaturedConcerts {
smartCollection(slug: "featured-concerts") {
title
targetCollection
items(limit: 6) {
totalDocs
docs {
__typename
title
path
... on Event { startDate }
}
}
}
}smartCollections lists every smart collection of the site.
Related
- Content model
- Theme blocks
- Custom objects: define custom object types in the admin.
- Custom attributes: add attributes to content types.