Skip to content

Latest commit

 

History

History

graphity-server-lambda

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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.