/node-lambda-graphql

AWS Lambda graphql handler

Primary LanguageJavaScriptMIT LicenseMIT

node-lambda-graphql

AWS Lambda graphql handler

Build Status

Installation

npm install --save lambda-graphql

Usage

  1. create Lambda function in AWS console

  2. install lambda-graphql and graphql modules

npm install --save lambda-graphql graphql

  1. create index.js...for example:
'use strict'

const graphql = require('graphql')
const lambdaGraphql = require('lambda-graphql')

const schema = graphql.buildSchema(`
  type Query {
    hello: String
  }
`)

const root = {
  hello: function(params) {
    return 'world'
  }
}

// options passed to lambdaGraphql() are the same as options for express-graphql module
let app = lambdaGraphql({
  schema: schema,
  rootValue: root
})

// pass handler as `index.handler` for aws lambda
exports.handler = app.handler

// shutdown gracefully (process in container is stopped before going to "sleep")
process.on('exit',() => {
  app.close()
})
process.on('SIGINT',process.exit)
  1. deploy function by uploading to AWS Lambda

  2. setup AWS Gateway API with proxy resource (for example /graphql) and forward requests (GET and POST methods) to created lambda function