0
0
GraphQLquery~5 mins

Enum types in GraphQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an Enum type in GraphQL?
An Enum type in GraphQL is a special kind of scalar that restricts a field to a set of predefined constant values. It helps ensure only valid values are used.
Click to reveal answer
beginner
How do you define an Enum type in GraphQL schema?
You define an Enum type using the enum keyword followed by the name and a list of allowed values inside curly braces. For example:<br>
enum Color { RED GREEN BLUE }
Click to reveal answer
intermediate
Why use Enum types instead of strings in GraphQL?
Enums provide a fixed set of allowed values, which helps catch errors early, improves API clarity, and makes client-server communication more predictable compared to free-form strings.
Click to reveal answer
intermediate
Can Enum types have descriptions for each value in GraphQL?
Yes, you can add descriptions to each Enum value using string comments above each value. This helps document the purpose of each option for API users.
Click to reveal answer
intermediate
How does GraphQL handle invalid Enum values in queries?
If a query provides a value not defined in the Enum, GraphQL returns an error and does not execute the query, ensuring only valid Enum values are accepted.
Click to reveal answer
Which keyword is used to define an Enum type in GraphQL?
Atype
Binterface
Cscalar
Denum
What happens if a query uses a value not in the Enum type?
AGraphQL ignores the value
BGraphQL converts it to a string
CGraphQL returns an error
DGraphQL accepts it anyway
Why are Enum types useful in GraphQL?
AThey restrict values to a fixed set
BThey allow any string value
CThey store large text data
DThey define database tables
Can Enum values have descriptions in GraphQL schema?
ANo, descriptions are not allowed
BYes, using comments above each value
COnly for the whole Enum, not values
DOnly in the client code
Which of these is a valid Enum definition?
Aenum Status { ACTIVE INACTIVE PENDING }
Benum Status = (ACTIVE, INACTIVE, PENDING)
Ctype Status { ACTIVE, INACTIVE, PENDING }
Dscalar Status { ACTIVE, INACTIVE, PENDING }
Explain what an Enum type is in GraphQL and why it is useful.
Think about how you limit choices to a list of options.
You got /3 concepts.
    Describe how to define an Enum type in a GraphQL schema with an example.
    Remember the syntax starts with 'enum' followed by the name.
    You got /4 concepts.