0
0
GraphQLquery~10 mins

Input types in GraphQL - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Input types
Define Input Type
Use Input Type in Query/Mutation
Client Sends Input Data
Server Validates Input
Execute Resolver with Input
Return Response
Input types are defined first, then used in queries or mutations where client sends data, server validates it, and resolver executes with that input.
Execution Sample
GraphQL
input UserInput {
  name: String!
  age: Int
}

mutation createUser($input: UserInput!) {
  addUser(input: $input) { id name }
}
Defines an input type UserInput and uses it in a mutation to add a user with name and optional age.
Execution Table
StepActionInput DataValidation ResultResolver CalledOutput
1Define Input Type UserInput----
2Client sends mutation with input {name: "Alice", age: 30}{"name":"Alice","age":30}ValidaddUser({name: "Alice", age: 30}){"id":"1","name":"Alice"}
3Client sends mutation with input {name: "Bob"}{"name":"Bob"}Valid (age optional)addUser({name: "Bob"}){"id":"2","name":"Bob"}
4Client sends mutation with input {age: 25}{"age":25}Invalid (name missing)No resolver callError: Field 'name' is required
5Client sends mutation with input {name: null}{"name":null}Invalid (name non-null)No resolver callError: Field 'name' cannot be null
💡 Execution stops when input validation fails or after resolver returns response.
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4After Step 5
inputundefined{"name":"Alice","age":30}{"name":"Bob"}{"age":25}{"name":null}
validationnonevalidvalidinvalidinvalid
resolverCalledfalsetruetruefalsefalse
outputnone{"id":"1","name":"Alice"}{"id":"2","name":"Bob"}errorerror
Key Moments - 3 Insights
Why does the mutation fail when 'name' is missing in the input?
Because 'name' is marked as non-nullable (String!), the validation fails at step 4 in the execution_table, so the resolver is not called.
Can the 'age' field be omitted in the input?
Yes, 'age' is optional (no !), so at step 3 the input without 'age' passes validation and resolver runs.
What happens if 'name' is explicitly set to null?
At step 5, validation fails because 'name' is non-nullable, so the mutation returns an error without calling the resolver.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the validation result at step 3?
AInvalid (missing name)
BValid (age optional)
CValid (all fields present)
DInvalid (name null)
💡 Hint
Check the 'Validation Result' column at step 3 in the execution_table.
At which step does the resolver NOT get called due to invalid input?
AStep 2
BStep 3
CStep 4
DStep 1
💡 Hint
Look at the 'Resolver Called' column in the execution_table for steps with 'false'.
If the 'name' field was made optional, how would step 4 change?
AValidation would pass and resolver would be called
BValidation would fail as before
CResolver would be called but return error
DNo change in validation
💡 Hint
Refer to the 'validation' variable in variable_tracker and how non-null affects validation.
Concept Snapshot
Input types define structured data for queries/mutations.
Use 'input' keyword with fields and types.
Non-null fields require values; optional fields can be omitted.
Server validates input before resolver runs.
Invalid input stops execution with error.
Input types improve data safety and clarity.
Full Transcript
This visual execution shows how GraphQL input types work step-by-step. First, an input type UserInput is defined with a required name and optional age. Then, clients send mutations with input data. The server validates this input: if required fields are missing or null, validation fails and the resolver is not called. If input is valid, the resolver executes and returns data. The execution table tracks each step, showing input data, validation results, resolver calls, and outputs. Variable tracking shows how input and validation states change. Key moments clarify common confusions about required vs optional fields and null values. The quiz tests understanding by referencing these visuals. This helps beginners see exactly how input types control data flow in GraphQL.