⬡ GraphQL
Beginner
What are enum types in GraphQL?
Answer
Enum types define a set of allowed constant values for a field. They restrict a field to one of a predefined set of string values. Definition: enum UserRole { ADMIN EDITOR VIEWER }. Usage in a type: type User { id: ID! role: UserRole! }. In a query response, the value comes back as the string "ADMIN". In mutations: mutation { updateUser(id: "1", role: ADMIN) { role } } — note: enum values in queries are passed without quotes (unlike strings). Enums are useful for: status fields, roles, categories, directions. When an invalid enum value is passed, GraphQL validation rejects the request before execution. Enum values are all-caps by convention in GraphQL (though not enforced).