/graphql-free

Free serverless GraphQL implemented with apollo-server-lambda framework for nodejs

Primary LanguageJavaScript

Free GraphQL API

Prerequisites

  • nodejs v14
  • yarn
  • docker
  • docker-compose
  • AWS cli
  • SAM cli

Running project locally

Configure aws cli

Although the project will be run locally, setting up dynamodb requires that the aws cli has been properly configured

$ aws configure

Setup dynamodb

$ yarn setup-dynamodb

Running the GraphQL API

$ yarn start:graphql

Deploying

The deployment via cli uses CloudFormation. This means that, before deploying the API, it's necessary to create a S3 bucket that will hold the CloudFormation stack.

$ aws s3 mb s3://graphql-free-cf-template

The deployment happens in 2 steps:

  1. package: Transforms the SAM template file into a CloudFormation template (template-prod.yaml -> cf-template.yaml)
  2. deploy: Uses the CloudFormation file (cf-template.yaml) as "blueprint" to create/update the CloudFormation stack.

There's a script that does both steps at once, to make sure all steps are executed:

$ yarn deploy:graphql

Performance testing

Performance testing will be executed with k6. Please follow the installation instructions from their k6's docs.

To run the test, use the following command:

$ k6 run -e GRAPHQL_ENDPOINT=<api-endpoint> -e GOAL_ID=<goal-id> performance-k6.js --vus 2 --duration 30s

It runs the script performance-k6.js in endpoint http://localhost:3000/graphql with 2 virtuals users for 30 seconds. Feel free to change the parameters for your tests.

Note: Running the test is recommended to point to an envoriment that's close to production (i.e. use AWS's endpoint instead of localhost).