0
0
GraphQLquery~20 mins

Custom error extensions in GraphQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
GraphQL Error Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output of this GraphQL error response with custom extensions?

Consider a GraphQL query that triggers an error with custom extensions. What will the error response contain?

GraphQL
{
  "errors": [
    {
      "message": "User not found",
      "extensions": {
        "code": "USER_NOT_FOUND",
        "timestamp": "2024-06-01T12:00:00Z"
      }
    }
  ]
}
A{"errors":[{"message":"User not found","extensions":{"code":"USER_NOT_FOUND","timestamp":"2024-06-01T12:00:00Z"}}]}
B{"data":null,"errors":[{"message":"User not found"}]}
C{"errors":[{"message":"User not found","code":"USER_NOT_FOUND"}]}
D{"errors":[{"message":"User not found","extensions":{"errorCode":"USER_NOT_FOUND"}}]}
Attempts:
2 left
💡 Hint

Custom error extensions appear inside the extensions field in the error object.

🧠 Conceptual
intermediate
1:30remaining
Which field in a GraphQL error response holds custom error details?

In GraphQL, where do you put extra information like error codes or debug data in an error response?

AThe <code>message</code> field
BThe <code>locations</code> field
CThe <code>data</code> field
DThe <code>extensions</code> field
Attempts:
2 left
💡 Hint

Think about where extra metadata about errors is stored.

📝 Syntax
advanced
2:00remaining
Identify the invalid GraphQL error extension format

Which of the following GraphQL error objects has an invalid extensions field format?

A{"message":"Timeout","extensions":"TIMEOUT_ERROR"}
B{"message":"Invalid input","extensions":{"code":"BAD_INPUT"}}
C{"message":"Unauthorized","extensions":{"code":"UNAUTH"}}
D{"message":"Not found","extensions":{"code":"NOT_FOUND","retry":true}}
Attempts:
2 left
💡 Hint

The extensions field must be an object, not a string.

🔧 Debug
advanced
2:30remaining
Why does this GraphQL error extension not appear in the client response?

A server returns this error object but the client does not see the extensions field. What is the likely cause?

{
  "errors": [
    {
      "message": "Access denied",
      "extensions": null
    }
  ]
}
AThe <code>message</code> field is missing
BThe client filters out <code>extensions</code> by default
CThe server must send <code>extensions</code> as an object, not null
DGraphQL does not support <code>extensions</code> in errors
Attempts:
2 left
💡 Hint

Check the type of the extensions field.

optimization
expert
3:00remaining
How to efficiently include error codes in GraphQL responses for multiple errors?

You want to send multiple errors with custom codes in a GraphQL response. Which approach is best for performance and clarity?

AOmit error codes to reduce response size
BInclude a separate <code>extensions</code> object with a <code>code</code> field for each error
CEmbed error codes inside the <code>message</code> string for each error
DSend one <code>extensions</code> object at the root with all error codes combined
Attempts:
2 left
💡 Hint

Think about how GraphQL error objects are structured.