Closed Sebas1245 closed 1 year ago
I'm getting the same error. Works with createAPIGatewayProxyEventRequestHandler
but not createAPIGatewayProxyEventV2RequestHandler
.
Can you provide your serverless.yml
file? I suspect that you might be using a lambda event source that only supports the V1 event. As fellow Daniel, @daniel-keller mentioned, if that is the case you will need to utilize the createAPIGatewayProxyEventRequestHandler()
function. Event sources that utilize V1 and V2 events are not cross compatible.
If you are following the documentation here, this should set you up to use the V2 event type. If this is incorrect please let me know and I will investigate further.
Yeah I think I followed the documentation you specified, except I'm using Node v18. The lambda event source on serverless.yml
file is as follows:
functions:
graphql:
handler: src/graphql-api/apollo-server.graphqlServer
events:
- http:
path: graphql
method: post
cors: true
- http:
path: graphql
method: get
cors: true
Can you provide your
serverless.yml
file? I suspect that you might be using a lambda event source that only supports the V1 event. As fellow Daniel, @daniel-keller mentioned, if that is the case you will need to utilize thecreateAPIGatewayProxyEventRequestHandler()
function. Event sources that utilize V1 and V2 events are not cross compatible.If you are following the documentation here, this should set you up to use the V2 event type. If this is incorrect please let me know and I will investigate further.
This solved the problem for me on my local while running tests. In my tests I was using a mocked event APIGatewayProxyEvent
and pairing it with createAPIGatewayProxyEventV2RequestHandler
which resulted in the error. Mocking a APIGatewayProxyEventV2
event solved the problem.
However, I misunderstood what V1 vs V2 api gateway events meant. V1 refers to API Gateway's REST APIs while V2 refers to the HTTP and WebSocket APIs. They are not interchangeabl. I actually have to use V1 events b/c I need features only provided by V1
@Sebas1245 In the serverless yml events http
are for V1 Proxy events and httpApi
is for V2
This config requires using createAPIGatewayProxyEventRequestHandler
functions:
graphql:
handler: src/graphql-api/apollo-server.graphqlServer
events:
- http: <=== these should be httpApi for createAPIGatewayProxyEventV2RequestHandler to work
path: graphql
method: post
cors: true
- http: <====
path: graphql
method: get
cors: true
Hi there. I tried following the example given on the official Apollo documentation to find out that using
handlers.createAPIGatewayProxyEventV2RequestHandler()
and trying to open the Apollo Server playground results in aCannot read properties of undefined (reading 'method')
response from the browser. Downgrading to the original version has it working just fine, so I'm guessing this is a bug with V2.I'm using Node.JS LTS/Hydrogen with Typescript with the following dependencies
This is the code I'm using to create the Lambda handler