Enumeration Types

Learn enumeration types and their use in GraphQL.

We'll cover the following...

Using enumeration types

A GraphQL enumeration (or enum) is a special type of scalar that has a defined, finite set of possible values. Here are some examples of values that are well represented by enums:

  • Available shirt sizes: S, M, L, and XL.
  • Color components: RED, GREEN, and BLUE.
  • Ordering: ASC and DESC.

Enums are a good choice if the possible values are well-defined, unlikely to change, and are not a pair of values that would be clearly represented by a boolean flag.

Let’s use the ASC and DESC ordering examples for a list of menuItems that we’ll allow users to retrieve in ascending or descending order.

We’ll start by adding our enum type, :sort_order, using the enum and value macros. The enum ...