Last updated
Validation Levels Summary
- Lexical — valid GraphQL tokens (no invalid characters)
- Syntax — valid GraphQL grammar (braces, colons, commas)
- Schema — fields and types exist in the schema
- Type — argument and variable types match
- Semantic — fragments on compatible types, variables declared and used
- Complexity — depth and complexity within acceptable limits
- Best practices — mutations return data, lists are paginated
- Deprecation — deprecated fields flagged with migration guidance
Examples
Example 1: Syntax Errors
# Error: Missing closing brace
query GetUser($id: ID!) {
user(id: $id) {
id
name
# ← missing }
Validation Error:
Syntax Error: Expected "}", found EOF
Location: Line 6, Column 1
Fix: Add closing "}" after the "name" field
# Error: Invalid field name (starts with number)
query {
user {
1name # ← invalid identifier
}
}
Validation Error:
Syntax Error: Expected Name, found Int "1"
Location: Line 3, Column 5
Fix: Field names must start with a letter or underscore
Example 2: Schema Validation Errors
# Schema:
type User {
id: ID!
name: String!
email: String!
}
# Query referencing non-existent field:
query {
user(id: "123") {
id
name
phoneNumber # ← doesn't exist
address { # ← doesn't exist
city
}
}
}
Validation Errors:
1. Field "phoneNumber" does not exist on type "User"
Available fields: id, name, email
Location: Line 6, Column 5
2. Field "address" does not exist on type "User"
Available fields: id, name, email
Location: Line 7, Column 5
Example 3: Type Mismatch Errors
# Schema:
type Query {
user(id: ID!): User
posts(limit: Int): [Post!]!
}
# Query with wrong argument types:
query {
user(id: 123) # ← Int passed, ID expected
posts(limit: "10") # ← String passed, Int expected
}
Validation Errors:
1. Argument "id" has invalid value 123.
Expected type "ID", found Int.
Fix: Use id: "123" (string)
2. Argument "limit" has invalid value "10".
Expected type "Int", found String.
Fix: Use limit: 10 (integer, no quotes)