@graphity/server-lambda
TypeScript icon, indicating that this package has built-in type declarations

0.9.2 • Public • Published

Graphity - Server Lambda

Downloads Version License Typescript
dependencies Status

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.

Package Sidebar

Install

npm i @graphity/server-lambda

Weekly Downloads

1

Version

0.9.2

License

MIT

Unpacked Size

11.1 kB

Total Files

13

Last publish

Collaborators

  • wan2land