Bird
0
0

You want to add a new field 'age' to User type that is optional but must be an integer if present. How do you define it in SDL?

hard📝 Application Q8 of 15
GraphQL - Basics and Philosophy
You want to add a new field 'age' to User type that is optional but must be an integer if present. How do you define it in SDL?
Aage?: Int
Bage: Int!
Cage: Int?
Dage: Int
Step-by-Step Solution
Solution:
  1. Step 1: Understand optional field syntax

    In SDL, absence of ! means the field is optional (nullable).
  2. Step 2: Choose correct syntax for optional integer

    'age: Int' means age can be null or an integer, matching requirement.
  3. Final Answer:

    age: Int -> Option D
  4. Quick Check:

    Optional field = type without ! [OK]
Quick Trick: No ! means field is optional (nullable) [OK]
Common Mistakes:
  • Using Int! makes field required
  • Using ? or ?: which are invalid in SDL
  • Confusing optional with non-null

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes