Bird
0
0

You want to create an input type for updating a user's profile where all fields are optional except id. Which input type definition is correct?

hard📝 Application Q15 of 15
GraphQL - Schema Definition Language (SDL)
You want to create an input type for updating a user's profile where all fields are optional except id. Which input type definition is correct?
Ainput UpdateUserInput { id: ID! name: String! email: String age: Int }
Binput UpdateUserInput { id: ID! name: String email: String age: Int }
Cinput UpdateUserInput { id: ID! name: String! email: String! age: Int! }
Dinput UpdateUserInput { id: ID name: String! email: String! age: Int! }
Step-by-Step Solution
Solution:
  1. Step 1: Understand requirement for optional fields

    Only id must be required (non-null). Other fields should be optional, so no exclamation marks.
  2. Step 2: Evaluate each option

    input UpdateUserInput { id: ID! name: String email: String age: Int } has id: ID! required and others optional. input UpdateUserInput { id: ID name: String! email: String! age: Int! } makes id optional and others required, wrong. input UpdateUserInput { id: ID! name: String! email: String! age: Int! } makes all fields required, wrong. input UpdateUserInput { id: ID! name: String! email: String age: Int } makes name required, which is not desired.
  3. Final Answer:

    input UpdateUserInput { id: ID! name: String email: String age: Int } -> Option B
  4. Quick Check:

    Only id required, others optional [OK]
Quick Trick: Only add '!' to required fields in input types [OK]
Common Mistakes:
  • Making all fields required
  • Forgetting to make id required
  • Adding '!' to optional fields

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes