Closed coyoteecd closed 1 year ago
After digging through the PRs, I think #67 covers this.
Thanks for the note! My intent is to wrap up #67 this weekend so we can get this pushed out. I'll add a note here when the PR is ready if you want to take a look.
@coyoteecd #67 is ready for review if you want to take a look. The updated README.md
would be a great place to see the new handler changes in-use.
This is now possible with V2.0.0! The following syntax should allow you to use custom authorizers.
export default startServerAndCreateLambdaHandler(
server,
handlers.createAPIGatewayProxyEventV2RequestHandler<
APIGatewayProxyEventV2WithLambdaAuthorizer<{
myAuthorizerContext: string;
}>
>(),
);
(The syntax will be the same for the V1 event, but I'm just not familiar with V1 typing)
As long as the provided optional type param extends the base proxy event, you'll be good to go!
(Bit late, sorry) Today I had the time to upgrade our project; version 2 covers my needs very well, thanks!
The current implementation of the context function uses an
IncomingEvent
that's defined as a union type: https://github.com/apollo-server-integrations/apollo-server-integration-aws-lambda/blob/fec618976880a6d499cf2dbfb02da2a71a4a96f3/src/index.ts#L20-L23This makes it inconvenient to define a context function that actually uses data from the event. A good example is the fact that
@types/aws-lambda
package includes type definitions for lambdas protected by an authorizer, in factAPIGatewayProxyEvent
is just assuming an "empty authorizer" as shown here. When the lambda is protected by an authorizer, one can define the handler using APIGatewayEventLambdaAuthorizerContext.This worked fine with apollo-server-lambda, because ApolloServer's constructor did not type the context function parameters. I am trying to upgrade our project to v4 and find myself being forced to force-cast the event type just to get it to compile properly.
Proposal I would like to have a generic parameter added that specifies the type of the event, with default being IncomingEvent. If one uses a custom authorizer, they can specify an event typed with the custom authorizer result.