Bird
0
0

You wrote this input type:

medium📝 Debug Q6 of 15
GraphQL - Mutations
You wrote this input type:
input UserInput { name: String, age: Int }

and mutation:
mutation createUser($input: UserInput!) { addUser(input: $input) { id } }

But when you run the mutation, you get an error: "Variable '$input' expected value of type 'UserInput!' but got null." What is the likely cause?
AThe input type must not have nullable fields
BYou did not provide the input variable when calling the mutation
CThe mutation name is incorrect
DYou used 'input' instead of 'user' as argument name
Step-by-Step Solution
Solution:
  1. Step 1: Understand required input variables

    The variable $input is required (due to !), so it cannot be null.
  2. Step 2: Identify cause of null error

    The error means the variable was not provided or was null when calling the mutation.
  3. Final Answer:

    You did not provide the input variable when calling the mutation -> Option B
  4. Quick Check:

    Required variable missing = null error [OK]
Quick Trick: Always provide required variables when calling mutations [OK]
Common Mistakes:
  • Assuming nullable fields affect variable presence
  • Confusing mutation name with variable name
  • Ignoring required variable syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GraphQL Quizzes