-
Notifications
You must be signed in to change notification settings - Fork 2k
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
apollo-server-lambda: Fix callback requirement for handler #5593
Conversation
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.
Hmm. I think you're right that we shouldn't claim we're implementing the @types/aws-lambda
Handler
since as of AS3 we don't pay attention to the callback. But if we're going to define our own type, shouldn't we just drop the callback
argument from the type entirely? I think that a passed callback gets ignored (if you dig in to @vendia/serverless-express
, we are using the default resolutionMode
of PROMISE
, so the callback is ignored).
Ahh, makes sense 👍 |
I think this doesn't build (because it doesn't match the type returned from |
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.
(should have clicked this button yesterday)
(Another option would be to send DefinitelyTyped a PR to make their type more flexible or to provide another non-callback handler type!) |
@glasser just ran into this today. what needs to be done to get this change merged? I'll pick up the effort tomorrow to make it happen. |
Unless something has changed, a PR to serverless-express to use type overloads to make its return type sensitive to how it is called would be best. |
I'm a bit confused. I don't see any mention of
Handler type. Are you saying you'd prefer that this package didn't maintain that type, and instead ask serverless-express to export a flexible Handler type?
|
So, as you can see in the CI, this PR does not compile. That is because the serverlessExpress function we depend on (the default export of this file: https://github.com/vendia/serverless-express/blob/mainline/src/configure.d.ts) says it returns one of aws-lambda's Handlers. That's a function that expects three non-optional arguments. So assigning that to a type that allows you to call it with only two arguments can't compile. Now, the serverlessExpress function is flexible: it takes a |
Any updates on this issue? |
Feel free to take over with your own PR — as described above, the PR as written does not build. Note that in the upcoming Apollo Server 4, the Lambda integration will be less tightly integrated into core and there can instead be multiple community approaches to Lambda integration — perhaps a direct implementation of the Lambda data structures, perhaps another using |
Apollo Server 4 replaces a hard-coded set of web framework integrations with a simple stable API for building integrations. As part of this, the core project no longer directly supports a Lambda integration. Check out the |
This is for #5592.
I copied the definition of
Handler
from@types/aws-lambda
and madecallback
optional, which fixes the issue.Hope this approach is alright, please let me know your thoughts.
Thanks!