Schema linting in GraphQL - Time & Space Complexity
When checking a GraphQL schema for errors or style issues, we want to know how long this process takes as the schema grows.
We ask: How does the time to lint change when the schema has more types or fields?
Analyze the time complexity of the following code snippet.
query LintSchema($schema: String!) {
lintSchema(schema: $schema) {
errors {
message
location
}
}
}
This query sends a schema string to a linting service that checks for errors and returns a list of problems found.
Look for repeated checks inside the linting process.
- Primary operation: Checking each type and each field in the schema.
- How many times: Once for every type and once for every field inside those types.
As the schema grows with more types and fields, the linting work grows too.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 types | About 10 checks for types plus checks for their fields |
| 100 types | About 100 checks for types plus checks for their fields |
| 1000 types | About 1000 checks for types plus checks for their fields |
Pattern observation: The work grows roughly in direct proportion to the number of types and fields.
Time Complexity: O(n)
This means the linting time grows linearly as the schema gets bigger.
[X] Wrong: "Linting time stays the same no matter how big the schema is."
[OK] Correct: More types and fields mean more checks, so linting takes longer as the schema grows.
Understanding how linting time grows helps you explain performance in real projects and shows you can think about scaling code.
"What if the linting also checked relationships between types? How would the time complexity change?"