0
0
GraphQLquery~20 mins

Enum types in GraphQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Enum Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output of this GraphQL enum query?

Given this GraphQL enum definition and query, what is the output?

enum Status {
  ACTIVE
  INACTIVE
  PENDING
}

type User {
  id: ID!
  name: String!
  status: Status!
}

query {
  user(id: "1") {
    name
    status
  }
}

Assume the user with id "1" has status ACTIVE.

A{"data": {"user": {"name": "Alice", "status": "ACTIVE"}}}
B{"data": {"user": {"name": "Alice", "status": "active"}}}
C{"data": {"user": {"name": "Alice", "status": 1}}}
D{"error": "Field 'status' is not defined"}
Attempts:
2 left
💡 Hint

Enum values in GraphQL are case sensitive and returned as defined.

🧠 Conceptual
intermediate
1:30remaining
Which statement about GraphQL enums is true?

Choose the correct statement about enums in GraphQL.

AEnum values must be unique and are case sensitive, usually uppercase without spaces.
BEnum values can be any string, including lowercase and spaces.
CEnum values can be numbers or booleans.
DEnum values are optional and can be omitted in queries.
Attempts:
2 left
💡 Hint

Think about how enums are defined and used in GraphQL schemas.

📝 Syntax
advanced
2:00remaining
Identify the syntax error in this enum definition

Which option correctly fixes the syntax error in this GraphQL enum?

enum Color {
  RED
  GREEN
  BLUE
  LIGHT BLUE
}
AAdd quotes around 'LIGHT BLUE'
BReplace 'LIGHT BLUE' with 'lightblue'
CReplace 'LIGHT BLUE' with 'LIGHT_BLUE'
DRemove 'LIGHT BLUE' entirely
Attempts:
2 left
💡 Hint

Enum values cannot contain spaces.

🔧 Debug
advanced
2:30remaining
Why does this GraphQL query fail with an enum argument?

Given this schema snippet:

enum Role {
  ADMIN
  USER
  GUEST
}

type Query {
  usersByRole(role: Role!): [User!]!
}

And this query:

query {
  usersByRole(role: "ADMIN") {
    id
    name
  }
}

Why does the query fail?

AThe enum value ADMIN is not defined in the schema
BEnum arguments must be passed without quotes, like role: ADMIN
CThe query must use lowercase enum values, like role: admin
DThe argument role must be omitted because it is optional
Attempts:
2 left
💡 Hint

Think about how enum values are passed as arguments in GraphQL queries.

optimization
expert
3:00remaining
Optimize this GraphQL schema using enums

You have a schema with a 'status' field as a string with possible values 'active', 'inactive', 'pending'. Which change optimizes the schema for better validation and clarity?

AChange 'status' to an integer representing each status
BKeep 'status' as a string but add comments listing possible values
CRemove 'status' field and use a boolean 'isActive' instead
DChange 'status' field type to an enum with values ACTIVE, INACTIVE, PENDING
Attempts:
2 left
💡 Hint

Enums help restrict values and improve schema clarity.