Q11: How do Enum types work in GraphQL?

Difficulty:EasyTopic:Types

Enumerations (Enums) are special scalar types restricted to a predefined set of allowed values. Enums ensure type safety when a argument or field must only take one of a small set of possible values.

Enum SDL Definition
enum Role {
  ADMIN
  USER
  GUEST
}

type User {
  id: ID!
  role: Role!
}
💡 The field role is guaranteed to return only one of the declared Enum values.
Key Takeaways
  • Enums validate field parameters against explicit allowed constant string choices.
Knowledge Check

Are Enum values in GraphQL SDL quotes-enclosed strings?