Field Types

Your schema is built up of GraphQL types. If you’re familiar working with GraphQL, you should feel right at home. GraphCMS supports all of the common GraphQL types you are used to, as well as some of its own.

You may also be interested in how input types work for filtering, ordering, paginating, and mutating data.

Here you will discover the core field types available when building your GraphCMS schema. Since your schema is automatically generated, it is recommended you browse the API Playground to get inspect all available field type definitions.

String

GraphCMS supports a few variations of the String field type. Strings are just strings, but depending on the variation you add to your model, it will reflect how it appears to content editors.

VariantDescription
Single line textMost used with headings, page titles, slugs, email, etc.
Multi line textMost used with strings that require no formatting, raw text like HTML, and XML where you control the parsing
MarkdownMarkdown is most used as an alternative to Rich Text. Enables advanced techniques such as MDX.

All 3 variations of the String type are queried in the same way, and return the strings of the field they represent:

Rich Text

The RichText field type is an advanced String field that returns your content in 4 different formats; raw, html, markdown, and text.

The Rich Text field renders an advanced textarea with tools to add headings, links, tables, images, lists, etc.

When a Rich Text field is added to your model, it will automatically generate the following types:

type RichText {
raw: RichTextAST!
html: String!
markdown String!
text: String!
}

For example, we can query all of those on our RichText field type content:

GraphCMS uses Slate 0.5 for Rich Text. You can see more about the RichTextAST here.

Integer

Integers are whole numbers, and are often used to reference price in cents, stock quantities etc..

For example, here we have products with a Int field for price:

Float

Floats are floating point numbers, and often represent fractional values. They are often used to describe values with precision, such as distance, weight, volume, etc.

For example, here we have products with a Float field for rating:

Boolean

Booleans default to null in GraphCMS, and can be true or false. You may opt to use a Boolean for specifying if a product is on sale, is part of a bundle, or a post accepts comments.

For example, here we have posts with a Boolean field for acceptsComments:

Date

The Date field type adheres to ISO 8601 standard. This means, October 7, 1989 is represented as 2018-11-07.

For example, here we have events with a Date for start:

Date and Time

Similar to the date field type, the DateTime field type adheres to ISO 8601 standard.

For example, here we have events with a DateTime for start:

JSON

GraphCMS has native field support for JSON (JavaScript Object Notation). This field is often used for storing large amounts of data from other systems.

For example, here we have products with a JSON field for metadata:

Asset

Assets are connected to models through a reference field. Assets can be any file type, not just images.

The Asset model comes its own default asset fields.

For example, here we have posts with a the Asset field for coverImage, querying those asset fields:

Learn more about Assets.

Color

The Color field is made up of HEX, RGBA and css color values.

type Color {
hex: Hex!
rgba: RGBA!
css: String!
}
FieldTypeDescription
hexHex!Returns a String in the format of #ffffff
rgbaRGBA!r, g, b, values as RGBAHue!, and a as RGBATransparency!
cssString!Returns in the format of rgb(255, 255, 255)

For example, here is posts with a Color field for backgroundColor, in all formats:

Location

The Location field type returns latitude, longitude, and distance Float values.

type Location {
latitude: Float!
longitude: Float!
distance(from: LocationInput!): Float!
}
FieldTypeDescription
latitudeFloat!Geographic coordinate (north-south position on Earth)
longitudeFloat!Geographic coordinate (east-west position on Earth)
distanceLocationInput!Distance in meters from the given latitude/longitude

To query the distance field, you must provide latitude and longitude values for the from argument.

For example, here we have all shop locations, with distance from the provided latitude/longitude:

Enumerations

Enumerations, or enum for short, are predefined list of values. They are defined inside your GraphQL schema, and can be referenced by any of your content models.

For example, here is are products with its commodity type:

Reference

References, often referred as relations, are a powerful field type that allows you to connect one or more models together, and even reference multiple models as a single field type with GraphQL Union Types.

For example, here we have an example of querying all products, with categories they belong to.

One to one

For example, a category can only have one product, and one product can only have one category.

One to many

For example, a category can have multiple products, but a product cannot belong to multiple categories.

Many to one

For example, a category has one product, but a product can belong to multiple categories.

Many to many

For example, a category can have many products, and products can belong to many categories.

Union

GraphQL Union Types are great for referencing different models as a single field.

For example, here we have a typical GraphQL query for fetching blocks on a page.

This field is configured to be either of type Hero, Grid, and/or Gallery:

{
pages {
blocks {
__typename
... on Hero {
title
ctaLink
}
... on Grid {
title
subtitle {
markdown
}
}
... on Gallery {
photos {
url
handle
}
}
}
}
}

Did you find this page useful?

Your feedback helps us improve our docs, and product.

This site uses cookies to provide you with a better user experience. For more information, refer to our Privacy Policy