serverless-graphql-boilerplate

A boilerplate template for serverless graphql (apollo) project

View project on GitHub

Serverless graphql boilerplate

:wrench: with :heart:

This is project template for apollo graphql server 2.0 with AWS lambda and AWS API Gateway with serverless framework. This template gives a quick way to start with your apollo graphql server with AWS services using serverless framework.

Quick Usage

Please make sure you have following:

  • node 8+
  • java 8 (if you want to use dynamodb local)
  • serverless (if you want to use sls install)

If you do not prefer to install serverless globally, then just use git clone

> sls install -u https://github.com/RishikeshDarandale/serverless-graphql-boilerplate -n myservice
OR
> git clone https://github.com/RishikeshDarandale/serverless-graphql-boilerplate myservice
> cd myservice
> npm install
> npx sls offline start --stage local

Note: please update your service name in serverless.yml

Apollo graphql server

This project template uses apollo-server-lambda to expose the graphql server as AWS lambda function. The graphql schema and resolvers are aranged in such fashion that each type and it’s resolvers will be in the same file. This will allow better management of your schema and maintenability of it. Just add a new [type].js and typeDef and resolvers as in the sample file, they will automatically sticted in main schema.

serverless configurations

Yes, this is needed in every project. This template maintains the configuration under ./config directory. Configuration is kept for per region per environment.

Serveless plugins

  • serverless-offline

To emulate your lambda with API gateway, this template uses serverless-offline plugin.

  • webpack

To optimize and bundle all dependencies for lambda deployment, this template uses serverless-webpack plugin.

  • serverless-dynanodb-local

To emulate dynamodb service, this template uses serverless-dynamodb-local plugin

Project Layout

serverless-graphql-boilerplate
|-- CONTRIBUTING.md
|-- README.md
|-- config    // configuration related to project
|   `-- us-east-1
|       |-- development.yml
|       |-- local.yml
|       `-- production.yml
|-- functions // graphql function which will have apollo graphql server 2.0 entrypoint
|   `-- graphql.js
|-- package-lock.json
|-- package.json
|-- seed      // dynamodb table seed data
|   `-- example.json
|-- serverless.yml
|-- src
|   |-- aws-resources // other aws resources for this stack
|   |   |-- dynamodb-table.yml
|   |   `-- lambda-role.yml
|   |-- graphql      // graphql schema and resolvers
|   |   |-- schema.js
|   |   `-- type.js
|   |-- libs         // source code
|   |   `-- utils
|   |       `-- LogUtils.js
|   `-- tests        // unit / integration tests
`-- webpack.config.js

Going forward

serverless world is unlimited, please feel free to update your project with other plugins as per your need.

I am still tempting to add linting, prettier, commitlint and husky to this project, but holding back as other project may have different needs. Please feel free to refer my other(website-deploy or apollo-dataSource-soap) project for these configurations.

Contributing

:star: Star me on GitHub — it helps!

:heart: contribution: Here is contributing guide in deatil.

For impatient here are quick steps:

  • Fork the repository
  • Create Branch in you local repository
  • while(youFinish) { Commit }
  • Squash related commits.
  • Write unit test cases for your work.
  • Check the Build on your local.
  • Raise a Pull Request (aka PR)