What are Enums?

Enumeration

Enumerations, enums for short, are not as commonly used in content projects! On a basic level, they function like a dropdown where the selected option must be predefined.

If you have an enumeration that describes a book's print status as In Print, Out of Print - we know that it can only be one of those two options and it forces content editors to use only of the allowed values.

For more information, visit Enum Concepts.

Creating an Enum

Creating an Enum is very easy! Click on the blue button "Create Enumeration" and you'll be presented with a screen like this.

'Creating an Enum'

Display Name

The Display Name helps you identify the Enum later on.

API ID

The API ID is generated automatically but you can override this with something custom if you prefer. Most users will leave this alone. This is how you will refer to the Enum from the API later on.

Enum API IDs can't be one of the following reserved words: status, int, float, string, boolean, id, enum, interface, union, fragment, type, datetime, json, mutation, scalar, query, input.

Description

A short description to help explain the intended use of this field.

Possible Values

These are the unique values of the Enum. They must begin with an uppercase letter.

Using an Enum in a Model

To use an enum in a model, your enumeration already needs to be created.

  1. Drag a Dropdown field into your model
  2. Give your field a display name and choose which enum you want the field to reference with the dropdown.
  3. You will now have access to your enumeration in a dropdown UI in the content view of this model!

Using an Enum in your code

Use an enumeration as a filter on your graphql queries! Here is an example using the FAQcards model from our website:

query {
  gcms {
    faqCards(where: {faqSection: PaymentAndPricing}) {
      question
      answer {
        markdown
      }
      faqSection
    }
  }
}

If you're using multiple of the Enum values on the same page (and same query), you'll need to alias the query to differentiate. Using a fragment is a great practice in this instance as well.

fragment Details on faqCards {
  question
    answer {
      markdown
    }
    faqSection
}

query {
  gcms {
    Pricing: faqCards(where: {faqSection: PaymentAndPricing}) {
      ...Details
    }
    About: faqCards(where: {faqSection: About}) {
      ...Details
    }
    TechAndFeatures: faqCards(where: {faqSection: TechnologyAndFeatures}) {
      ...Details
    }
  }
}