0
0
GraphQLquery~20 mins

Why error handling differs from REST in GraphQL - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
GraphQL Error Handling Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
How does GraphQL error handling differ from REST?
In REST APIs, errors are usually indicated by HTTP status codes. How does GraphQL handle errors differently?
AGraphQL returns errors only in HTTP headers, not in the response body.
BGraphQL uses HTTP status codes like 404 or 500 to indicate errors, similar to REST.
CGraphQL always returns HTTP 200 status and includes errors inside the response body under an 'errors' field.
DGraphQL does not provide any error information in the response.
Attempts:
2 left
💡 Hint
Think about how GraphQL separates transport status from query execution results.
query_result
intermediate
2:00remaining
Identify the GraphQL error response structure
Given a GraphQL query that requests a user by ID but the user does not exist, which response shows the correct error handling?
GraphQL
{ user(id: "123") { name email } }
A{ "data": { "user": null }, "errors": [{ "message": "User not found", "path": ["user"] }] }
B{ "error": "User not found", "status": 404 }
C{ "data": null, "status": 404 }
D{ "data": { "user": { "name": "", "email": "" } } }
Attempts:
2 left
💡 Hint
Look for the 'errors' field inside the response body.
📝 Syntax
advanced
2:00remaining
Which GraphQL error response is syntactically valid?
Select the syntactically valid GraphQL error response JSON for a failed query.
A{ "data": null, "errors": [{ "message": "Invalid query" }] }
B{ data: null, errors: [{ message: "Invalid query" }] }
C{ "data": null, "errors": { "message": "Invalid query" } }
D{ "data": null, "errors": [{ message: "Invalid query" }] }
Attempts:
2 left
💡 Hint
Remember JSON requires double quotes around keys and string values.
optimization
advanced
2:00remaining
Optimizing error handling in GraphQL responses
Which approach best optimizes error handling in GraphQL to avoid sending unnecessary data when a critical error occurs?
AAlways return full data even if errors occur to keep response size consistent.
BReturn null for 'data' and include detailed error messages in the 'errors' array.
CReturn partial data with errors and let the client handle missing fields.
DUse HTTP status codes to indicate errors and omit the 'errors' field.
Attempts:
2 left
💡 Hint
Consider how to clearly communicate critical failures without confusing partial data.
🔧 Debug
expert
2:00remaining
Why does this GraphQL client fail to detect errors?
A client sends a GraphQL query and checks HTTP status code to detect errors. It ignores the response body. Why might this approach fail?
ABecause the client must parse XML responses to find errors.
BBecause the client should check HTTP headers for error details instead.
CBecause GraphQL never returns errors in the response body, only status codes.
DBecause GraphQL returns HTTP 200 status even when there are errors inside the response body.
Attempts:
2 left
💡 Hint
Think about how GraphQL separates transport success from query success.