What are GraphQL enums?
Answer
Enums (enumeration types) in GraphQL represent a set of allowed string values for a field. They are declared with the enum keyword: enum Role { ADMIN EDITOR VIEWER }. Enum values are validated by the schema — passing an invalid value causes a schema validation error. Enums are internally represented as strings but are type-safe at the schema level. They're useful for status fields (OrderStatus: PENDING, PROCESSING, SHIPPED, DELIVERED), user roles, sort directions (OrderDirection: ASC, DESC), and any other fields with a finite set of valid values. Unlike scalars, enum values are visible in introspection.
Previous
What is batch loading in GraphQL and how does it improve performance?
Next
What is Apollo Federation and how do subgraphs, gateways, and directives like @key and @extends work?
More GraphQL Questions
View all →- Intermediate What is the N+1 problem in GraphQL and how does DataLoader solve it?
- Intermediate What are persisted queries in GraphQL?
- Intermediate What is the difference between schema-first and code-first GraphQL approaches?
- Intermediate What are the pagination strategies in GraphQL?
- Intermediate How is authentication handled in GraphQL?