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?"
Practice
Solution
Step 1: Understand partial success response structure
Partial success responses include both data that was successfully fetched and errors for parts that failed.Step 2: Identify fields present in response
The response contains adatafield with available data and anerrorsfield describing issues.Final Answer:
Bothdataanderrorsfields -> Option BQuick Check:
Partial success = data + errors [OK]
- Thinking partial success returns only data
- Assuming errors field is empty on partial success
- Believing partial success means no errors
Solution
Step 1: Understand error reporting in GraphQL
Errors are reported in theerrorsfield as an array when present.Step 2: Identify correct error check
Checking ifresponse.errorsexists and is not empty correctly detects errors.Final Answer:
Check ifresponse.errorsexists and is not empty -> Option AQuick Check:
Errors field presence = error check [OK]
- Checking data for null instead of errors
- Using HTTP status code instead of errors field
- Looking for message text instead of errors array
{"data": {"user": null}, "errors": [{"message": "User not found"}]} What should the client do?Solution
Step 1: Analyze the response data and errors
Theuserfield is null and there is an error message "User not found".Step 2: Decide client action based on partial success
The client should check errors and handle the missing user data appropriately, not ignore errors or blindly use null data.Final Answer:
Check theerrorsand handle missinguser-> Option AQuick Check:
Errors present + null data = handle carefully [OK]
- Using null data as valid without checking errors
- Ignoring errors field completely
- Retrying query without fixing cause
{"data": {"posts": [{"id": "1", "title": "Hello"}]}, "errors": [{"message": "Failed to fetch comments"}]} What is the likely cause of the error?Solution
Step 1: Examine data and errors in response
Data forpostsis present, but error message says "Failed to fetch comments".Step 2: Interpret partial success meaning
Partial success means some parts succeeded (posts), others failed (comments).Final Answer:
Posts data fetched but comments part failed -> Option DQuick Check:
Data present + error message = partial failure [OK]
- Assuming entire query failed with some data
- Thinking syntax error causes partial success
- Blaming network loss without evidence
users and their posts, knowing posts might fail?Solution
Step 1: Understand partial success handling in GraphQL
GraphQL allows querying multiple fields; some may succeed while others fail, returning partial success.Step 2: Design query and client logic
Request bothusersandpostsin one query, then checkerrorsto handle posts failures gracefully without losing users data.Final Answer:
Requestusersandpostsin one query and checkerrorsfor posts failures -> Option CQuick Check:
One query + error check = graceful partial success [OK]
- Splitting queries unnecessarily
- Ignoring errors and using incomplete data
- Confusing mutations with queries
Ready to prove it?
Pass the test and this pattern moves unknown
