Recall & Review
beginner
What are custom error extensions in GraphQL?
Custom error extensions are additional fields added to GraphQL error responses to provide more details about the error, such as error codes or extra context.
Click to reveal answer
intermediate
How do you add custom error extensions in a GraphQL resolver?
You throw an error with an 'extensions' property, for example: <br>
throw new ApolloError('Not found', 'NOT_FOUND', { resource: 'User' }) where the third argument adds custom extensions.Click to reveal answer
beginner
Why use custom error extensions instead of just error messages?
Custom extensions allow clients to programmatically identify error types and handle them differently, improving user experience and debugging.
Click to reveal answer
beginner
What is the standard field name for custom error details in GraphQL errors?
The standard field name is 'extensions'. It is an object that can hold any extra information about the error.
Click to reveal answer
intermediate
Give an example of a custom error extension field you might add.
You might add a field like
{ code: 'UNAUTHENTICATED', timestamp: '2024-06-01T12:00:00Z' } to indicate the error type and when it happened.Click to reveal answer
What is the purpose of the 'extensions' field in a GraphQL error?
✗ Incorrect
The 'extensions' field holds extra details about the error to help clients understand and handle it.
How do you include custom error extensions when throwing an error in Apollo Server?
✗ Incorrect
ApolloError accepts a third argument for extensions, allowing you to add custom error details.
Which of these is NOT a good reason to use custom error extensions?
✗ Incorrect
Sensitive data like passwords should never be included in error extensions.
What type of data can the 'extensions' field contain?
✗ Incorrect
The 'extensions' field can hold any data that can be converted to JSON.
If you want to indicate an error is due to authentication failure, which extension code might you use?
✗ Incorrect
'UNAUTHENTICATED' is commonly used to indicate authentication errors.
Explain how custom error extensions improve error handling in GraphQL.
Think about why just an error message might not be enough.
You got /4 concepts.
Describe how to add custom error extensions in a GraphQL resolver using Apollo Server.
Focus on the ApolloError constructor parameters.
You got /4 concepts.