NodeJS GraphQL DynamoDB
Description
An exemplary implementation of GraphQL API and AWS DynamoDB. API contains two endpoints:
- Query configurations(userId) - lets retrieve configurations related to custom userId.
- Mutation saveConfigurations(api, name, userId) - lets to save configuration in database.
Exemplary query and mutation can be found in unit tests spec(test/Configuration.spec.ts).
Runing the workflow
- Install dependencies and build using
npm install
. - Copy
example.env
as.env
and update it according to details of a target DynamoDB. - Run yoga server using
npm start
. - GraphQL Playground will be available on http://localhost:4000. API will be available for external clients on http://localhost:4000/graphql.
- To re-build the server use
npm build
.
Unit tests
- Install dependencies and build using
npm install
. - Copy
example.env
as.env
. - Run yoga server using
npm start
. - Install Docker Compose, run the Docker and update
.env/DYNAMODB_URL
withDocker default machine IP
:4569, e.g.SQS_URL=http://localhost:4569
- Run the Local Stack by command:
npm run startLocalStack
- Create a DynamoDB table by AWS CLI command:
aws --endpoint-url=http://192.168.99.100:4569 dynamodb create-table --table-name configuration --attribute-definitions AttributeName=id,AttributeType=S AttributeName=userId,AttributeType=S AttributeName=name,AttributeType=S --key-schema AttributeName=id,KeyType=HASH --global-secondary-indexes "[{\"IndexName\": \"userId-index\",\"KeySchema\":[{\"AttributeName\":\"userId\",\"KeyType\":\"HASH\"}], \"ProvisionedThroughput\": {\"ReadCapacityUnits\": 10, \"WriteCapacityUnits\": 5 },\"Projection\":{\"ProjectionType\":\"ALL\"}}, {\"IndexName\": \"name-index\",\"KeySchema\":[{\"AttributeName\":\"name\",\"KeyType\":\"HASH\"}], \"ProvisionedThroughput\": {\"ReadCapacityUnits\": 10, \"WriteCapacityUnits\": 5 },\"Projection\":{\"ProjectionType\":\"ALL\"}}]" --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5
. In above command, use you Docker machine IP(eghttp://localhost
orhttp://192.168.99.100
). - To run unit tests execute
npm test
.
Notes:
- GraphQL will be created when API will be started.
- Implemented based on graphql-api
- During the implemented was used node v10.16.3.