-
Notifications
You must be signed in to change notification settings - Fork 167
feat(event-handler): add support for error handling in AppSync GraphQL #4317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(event-handler): add support for error handling in AppSync GraphQL #4317
Conversation
…DatabaseError in AppSyncGraphQLResolver
… error types in AppSyncGraphQLResolver
…in AppSyncGraphQLResolver
…ame for better clarity
…n is based on error class name
|
I have one observation: while looking into the Python documentation, I realized they also accept list of errors for exception handling. Should we support that as well? |
Yes, that's what I'm doing in the API Gateway event handler so we should be consistent:
|
@@ -2,7 +2,7 @@ | |||
FROM squidfunk/mkdocs-material@sha256:bb7b015690d9fb5ef0dbc98ca3520f153aa43129fb96aec5ca54c9154dc3b729 | |||
|
|||
# Install Node.js | |||
RUN apk add --no-cache nodejs=22.13.1-r0 npm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, as other version is failing in my local
|
||
You can use the **`exceptionHandler`** method with any exception. This allows you to handle common errors outside your resolver and return a custom response. | ||
|
||
You can use a VTL response mapping template to detect these custom responses and forward them to the client gracefully. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The recommended way to do response mapping is JS now, not VTL, so we should include an example of how to do it that way.
} | ||
|
||
this.#logger.debug(`No exception handler found for error: ${errorName}`); | ||
return undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We return null
in the API Gateway handler so let's do the same here.
context | ||
); | ||
|
||
// Assess |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test should have have an assertion somewhere to ensure that the this
context is being preserved.
/** | ||
* Checks if there are any registered exception handlers. | ||
*/ | ||
public hasHandlers(): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this function? I think it's sufficient for the client to call resolve
and check whether it returns null
or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that can also be done too
Summary
This PR adds support for error handling in AppSync GraphQL described in the issue
Changes
exceptionHandler
method is introduced to register an exception and its handler.ExceptionHandlerRegistry
is introduced to keep track of registered exception handlersexceptionHandler
is also exposed as a decorator methodendregion
added)Lambda handler:
Response mapping template
Response:
Issue number: closes #4130
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.