Infrastructure

Create a serverless GraphQL implementation ready production, including CI/CD.

Developers should be able to just clone, add AWS credentials, and deploy away using GitHub Actions.

AWS Playground GitHub Repo

Implementation details

Use apollo-server-lambda npm package to serve the Apollo GraphQL through AWS Lambda.
It exposes the API to the Apollo implementation.

src/main.js#L1 view raw
const { ApolloServer, gql } = require('apollo-server-lambda');

GraphQL playground

The playground provides a GUI for making GraphQL requests. E.g. GitHub’s Playground

When running locally, the playground is enabled by default. However, if you wish to have the playground available when deploying to AWS infrastructure, there is an additional step to take.
Instruct the Lambda, when the requested HTTP method is GET, to server playground UI:

src/main.js view raw
return server.createHandler()(
  { ...event, path: event.requestContext.path || event.path },
  lambdaContext,
  callback,
);

CORS

Modify the AWS SAM template to allow all CORS.

template.yml#L5 view raw
ApiGatewayApi:
  Type: AWS::Serverless::Api
  Properties:
    StageName: "Prod"
    Cors: "'*'"