Partial success responses in GraphQL - Time & Space Complexity
When a GraphQL query returns partial success, some requested data is fetched while other parts fail.
We want to understand how the time to get this partial data grows as the query size increases.
Analyze the time complexity of this GraphQL query with partial success handling.
query GetUsersAndPosts {
users {
id
name
posts {
id
title
}
}
}
This query fetches users and their posts. Some posts may fail to load, resulting in partial success.
Look for repeated data fetching steps in the query.
- Primary operation: Fetching each user and then fetching their posts.
- How many times: Once for all users, and once per user for posts.
As the number of users grows, the total fetch operations increase.
| Input Size (n users) | Approx. Operations |
|---|---|
| 10 | About 1 fetch for users + 10 post fetches |
| 100 | About 1 fetch for users + 100 post fetches |
| 1000 | About 1 fetch for users + 1000 post fetches |
Pattern observation: Operations grow roughly in direct proportion to the number of users.
Time Complexity: O(n)
This means the time to get partial success data grows linearly with the number of users requested.
[X] Wrong: "Partial success means the query runs faster regardless of size."
[OK] Correct: Partial success only means some data failed, but the query still processes all requested items, so time grows with input size.
Understanding how partial success affects query time helps you explain real-world API behavior clearly and confidently.
"What if the query requested posts for only half the users? How would the time complexity change?"