alexdebrie / graphql-dynamodb-single-table

Example application showing how to use single-table design with GraphQL and DynamoDB
35 stars 12 forks source link

GraphQL + DynamoDB -- Single-table example

This repository includes an example of building a GraphQL API with DynamoDB using a single DynamoDB table. It is intended to pair with this guide on using DynamoDB in a GraphQL API.

Table of Contents

Usage

This application uses the AWS CDK to deploy a GraphQL API to AWS AppSync. Be sure to install and bootstrap the CDK before use.

To deploy, clone this repository and run the following commands:

npm i
cdk deploy

This will deploy an AppSync API and return the GraphQL root URL and an API key to access the API.

You can query the API in the AWS console, or you can open the index.html file to use a local GraphQL explorer. Before opening the file, be sure to replace GRAPHQL_ROOT and API_KEY with the received values from your deploy.

Application background

This sample application builds a portion of a SaaS blog hosting platform. Users create a Site on the platform and are able to create Posts on the site. Other users can view the Posts and attach a Comment to a Post.

The simplified ERD is below. This application includes the general CDK code and AppSync resolvers to demonstrate the key differences between single-table and multi-table design with GraphQL + DynamoDB.

AppSync - ERD

Takeaways