Giter VIP home page Giter VIP logo

serverless-graphql's Introduction

Serverless GraphQL

This starter kit is an opinionated set of tools combined to help you get started building a Serverless application with an GraphQL endpoint and deploy them to production in minutes.

This example uses the following technologies:

  • Serverless
  • GraphQL-js
  • Relay
  • React
  • CSSModules
  • Webpack
  • Jest

Install & Run

You need to have node 6 or higher installed.

npm install -g serverless
npm install

Use mocked data (keep in mind due hard-coded data the interface might behave not as expected)

npm run update-schema
npm start
# visit http://localhost:3000 in your browser

Use live data from the development environment. You need to make sure you have access to your deployed lambda functions. This works only after you deployed it to production.

npm run update-schema
npm run start:remote
# visit http://localhost:3000 in your browser

Setup for Production

AWS has global unique bucket names. You need to replace <your-s3-bucket-name> in package.json as well as in the serverless.yml with your own custom name.

Since the URL of the API is unknown until you create a stack, you need to deploy once without expecting the application to work using npm run deploy. After the initial deploy you can see the API url which you need to provide to the URL entry in security.env.prod.

deploy feedback

After these steps you are good to go and with your next npm run deploy your infrastructure should up and running. Visit http://<your-s3-bucket-name>.s3-website-us-east-1.amazonaws.com in your browser.

Developing

If you make changes to the GraphQL schema stop the server, regenerate it and restart the server:

npm run update-schema
npm start

Testing

We use Jest as a test runner. To run all tests use

npm run test

To update component snapshots after updating a component use

npm run test:update

Security

At Serverless we keep our keys encrypted in the repository. We recommend you to do the same. In our case deploying to a staging and production system is done via a continuous integration system which has knows about the secret to decrypt the necessary file with the environment variables. For demo purposes this repository has an unencrypted file for environment variables at foundation/environment/security.env.local and foundation/environment/security.env.prod.

Multiple package.json

In order to keep the total amount of code uploaded to AWS Lambda small the api directory containing the Serverless service has it's own package.json. This speeds up uploading and also should reduce the cold start time of Lambda functions. You don't have to run npm install manually at any point. It will only happen during deploy, but you need make sure every library you are consuming in your GraphQL endpoint is add a#s depdendency there.

package.json

  • depdendencies: depdendencies used by the front-end
  • devDepdendencies: depdendencies used to package the front-end application & running the local environment

api/package.json

  • depdendencies: depdendencies used on AWS Lambda

serverless-graphql's People

Contributors

ac360 avatar pmuens avatar minibikini avatar eahefnawy avatar nikgraf avatar brettstack avatar kevinold avatar marclar avatar laardee avatar denneulin avatar ryansb avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.