-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
147f315
commit 38dc4fa
Showing
1 changed file
with
24 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,32 @@ | ||
import { ApolloServer } from "apollo-server-lambda"; | ||
import { ApolloServer } from "@apollo/server"; | ||
import { APIGatewayProxyEvent } from "aws-lambda"; | ||
import { createConfig } from "./config"; | ||
import { Env, createConfig } from "./config"; | ||
import { handlers, startServerAndCreateLambdaHandler } from "@as-integrations/aws-lambda"; | ||
|
||
const server = new ApolloServer( | ||
createConfig( | ||
/** | ||
* Create a basic server, for use with `startServerAndCreateLambdaHandler` function | ||
*/ | ||
const server = new ApolloServer({ | ||
...createConfig( | ||
// Get environment-specific information from environment variables | ||
process.env, | ||
process.env as Env, | ||
(integrationContext: { event: APIGatewayProxyEvent }, headerName) => | ||
// Because we're running in an AWS Lambda, extract headers from the | ||
// lambda event | ||
integrationContext.event.headers[headerName] | ||
) | ||
); | ||
), | ||
}); | ||
|
||
exports.handler = server.createHandler(); | ||
export const handler = startServerAndCreateLambdaHandler( | ||
server, | ||
handlers.createAPIGatewayProxyEventV2RequestHandler(), | ||
{ | ||
middleware: [ | ||
async (event) => { | ||
console.log("###? received event body=" + JSON.stringify(event.body)); | ||
// @ts-ignore | ||
event.requestContext["http"] = { method: event.requestContext.httpMethod }; //have to do this otherwise error in request handler | ||
}, | ||
] | ||
} | ||
); |