serverless-boilerplate-graphql

0.0.3 • Public • Published

Serverless GraphQL Architecture Application Boilerplate

Serverless GraphQL Boilerplate

serverless

This boilerplate application features a serverless architecture that leverages new technologies (Lambda, GraphQL) to reach a very low total cost of ownership (i.e., least amount of code, administration, cost).


Setup

If you haven't yet installed serverless on your machin, run:

npm install -g serverless

then install the GraphQL Boilerplate in the CWD by running:

sls project install serverless-boilerplate-graphql
cd serverless-boilerplate-graphql

Back

Add the authTokenSecret variable to _meta/variables/s-variables-STAGE-REGION.json and give it a strong value. This is the secret used to generate JSON web tokens. Then:

cd back/api
npm install
sls function deploy --all
sls endpoint deploy --all

Client

Set API_URL in client/src/app/js/actions/index.js. Then:

cd ../../client/src
npm install
npm start

This will runs the client locally. You can then deploy the client to an S3 bucket with:

npm run build
sls client deploy

Deploying to S3 bucket

Make sure you're still in the client/src folder mentioned above, then run:

npm run build
sls client deploy

Testing With A Local DynamoDB Instance

  • Install Docker
  • Run docker-compose up to install and run DynamoDB.
  • Add the localDynamoDbEndpoint variable with the value http://<DOCKER-MACHINE-IP>:8000 to _meta/variables/s-variables-common.json. Example value: http://192.168.99.100:8000.
  • Run sls setup db -s <stage> -r <region> to create tables in the local DynamoDB instance.
  • Run sls offline start to start the offline server.

Testing With GraphiQL

If you're running OSX, you can use the GraphiQL Electron App to test the GraphQL backend without a client:

  • Install brew cask for easy installation: brew tap caskroom/cask
  • Install GraphiQL App: brew cask install graphiql
  • Open GraphiQL application. Just search for GraphiQL using OSX Spotlight Search!
  • Add your data endpoint to the "GraphQL Endpoint" text field, and make sure the "Method" is set to POST.
  • Try this mutation to create the first user:
mutation createUserTest {
  createUser (username: "serverless", name: "Serverless Inc.", email: "hello@serverless.com", password: "secret") {
    id 
    username 
    name 
    email  
  }
}
  • Now list all users using the following query:
query getUsersTest { 
  users {
    id
    username
    name
    email
  } 
}
  • You should get the user you just created:
{
  "data": {
    "users": [
      {
        "id": "aca42ee0-f509-11e5-bc11-0d8b1f79b4b9",
        "username": "serverless",
        "name": "Serverless Inc.",
        "email": "hello@serverless.com"
      }
    ]
  }
}

Team Workflow with Meta Sync Plugin

This boilerplate includes the Meta Sync Plugin. To start using it you need to add the following serverless variables to _meta/variables/s-variables-common.json:

"meta_bucket" : "SOME_BUCKET_NAME",
"meta_bucket_region" : "us-east-1" // or any other region

Team

Readme

Keywords

none

Package Sidebar

Install

npm i serverless-boilerplate-graphql

Weekly Downloads

0

Version

0.0.3

License

MIT

Last publish

Collaborators

  • ac360