Concept Flow - Input validation patterns
Receive Input
Check Type
Yes
Check Required Fields
Yes
Apply Validation Rules
Return Error
Input validation in GraphQL checks input type, required fields, and rules before running the query or mutation.
mutation AddUser($input: UserInput!) {
addUser(input: $input) {
id
name
}
}| Step | Action | Input State | Validation Check | Result |
|---|---|---|---|---|
| 1 | Receive input | {"name": "Alice", "age": 25} | Check type UserInput | Pass |
| 2 | Check required fields | name present, age present | All required fields present | Pass |
| 3 | Apply validation rules | age=25 | age >= 18 | Pass |
| 4 | Apply validation rules | name='Alice' | name length > 0 | Pass |
| 5 | Validation complete | All checks passed | Ready to execute mutation | Pass |
| 6 | Execute mutation | Add user to database | N/A | Success |
| 7 | Return result | User id and name | N/A | Success |
| Variable | Start | After Step 1 | After Step 2 | After Step 3 | Final |
|---|---|---|---|---|---|
| input | undefined | {"name": "Alice", "age": 25} | {"name": "Alice", "age": 25} | {"name": "Alice", "age": 25} | {"name": "Alice", "age": 25} |
| validationStatus | undefined | pending | pending | pending | passed |
GraphQL input validation: - Check input type matches schema - Verify all required fields present - Apply custom validation rules (e.g., age >= 18) - Fail early on errors - Proceed to execute mutation/query only if valid