@graphity/server-lambda
v0.9.2
Published
Super slim depdency injection container with Async/Promise for Javascript(& Typescript).
Downloads
47
Maintainers
Readme
Graphity - Server Lambda
Installation
npm install @graphity/server-lambda --save
import { APIGatewayProxyHandler } from 'aws-lambda'
import { Graphity } from 'graphity'
import { ServerLambda } from '@graphity/server-lambda'
const graphity = new Graphity({
resolvers: [
HomeResolver,
/* ... */
],
})
graphity.register(new AuthProvider())
graphity.register(new AwsProvider())
graphity.register(new TypeormProvider())
const server = new ServerLambda(graphity) // without boot
export const handler: APIGatewayProxyHandler = (event, ctx, callback) => server.execute(event, ctx, callback)
Options
interface ServerLambdaOptions {
callbackWaitsForEmptyEventLoop?: boolean
cors?: {
origin?: boolean | string | string[],
methods?: string | string[],
allowedHeaders?: string | string[],
exposedHeaders?: string | string[],
credentials?: boolean,
maxAge?: number,
}
}
CORS
To use CORS, simply set the following options.
const server = new ServerLambda(graphity, {
cors: {
origin: '*',
credentials: true,
},
})
callbackWaitsForEmptyEventLoop
When using a persistent connection such as a database, there may be no response. In this case, you can do the following:
const server = new ServerLambda(graphity, {
callbackWaitsForEmptyEventLoop: false,
})
For more information, see AWS Lambda Context Object in Node.js.