GraphQL - Basics and PhilosophyYou 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?: IntBage: Int!Cage: Int?Dage: IntCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand optional field syntaxIn SDL, absence of ! means the field is optional (nullable).Step 2: Choose correct syntax for optional integer'age: Int' means age can be null or an integer, matching requirement.Final Answer:age: Int -> Option DQuick Check:Optional field = type without ! [OK]Quick Trick: No ! means field is optional (nullable) [OK]Common Mistakes:Using Int! makes field requiredUsing ? or ?: which are invalid in SDLConfusing optional with non-null
Master "Basics and Philosophy" in GraphQL9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More GraphQL Quizzes GraphQL Basics and Philosophy - First GraphQL query - Quiz 1easy Mutations - Update mutation pattern - Quiz 14medium Queries - Aliases for field renaming - Quiz 6medium Queries - Query variables - Quiz 6medium Queries - Query arguments - Quiz 10hard Queries - Fragments for reusable selections - Quiz 7medium Resolvers - Resolver chains - Quiz 15hard Schema Definition Language (SDL) - Enum types - Quiz 10hard Type Relationships - One-to-one relationships - Quiz 6medium Type Relationships - One-to-many relationships - Quiz 1easy