Skip to content

jakubknejzlik/node-lambda-graphql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

AWS Lambda graphql handler

Resources

License

Stars

Watchers

Forks

Packages

No packages published