Skip to content

Commit 39efda1

Browse files
Fix recognition of API Gateway V1 events (#30)
Correctly handle gateway V1 events with version
1 parent dc06e69 commit 39efda1

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

.changeset/serious-fishes-act.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@as-integrations/aws-lambda': patch
3+
---
4+
5+
Correctly recognize gateway v1 events

src/__tests__/mockAPIGatewayV1Server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ function v1EventFromRequest(
3030

3131
// simplify the V1 event down to what our integration actually cares about
3232
const event: Partial<APIGatewayProxyEvent> = {
33+
// @ts-expect-error (version actually can exist on v1 events, this seems to be a typing error)
34+
version: "1.0",
3335
httpMethod: req.method!,
3436
headers: Object.fromEntries(
3537
Object.entries(req.headers).map(([name, value]) => {

src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@ function normalizeGatewayEvent(event: GatewayEvent): HTTPGraphQLRequest {
102102
}
103103

104104
function isV1Event(event: GatewayEvent): event is APIGatewayProxyEvent {
105-
return !('version' in event);
105+
// APIGatewayProxyEvent incorrectly omits `version` even though API Gateway v1
106+
// events may include `version: "1.0"`
107+
return (
108+
!('version' in event) || ('version' in event && event.version === '1.0')
109+
);
106110
}
107111

108112
function isV2Event(event: GatewayEvent): event is APIGatewayProxyEventV2 {

0 commit comments

Comments
 (0)