Skip to content

ericmaicon/todo-graphql

Repository files navigation

TODO GraphQL server

Commitizen friendly semantic-release code style: prettier

Prerequisites

  • Node.js
  • npm
  • Docker

Local development installation

Clone the repo and install the dependencies:

npm install

Setup the .env file as below if you will going to use the docker-compose file from the repo:

DATABASE_URL=postgresql://user:[email protected]:5432/todo
ACCESS_KEY=access
REFRESH_KEY=refresh

Start the docker containers to run a postgres locally:

docker compose up -d

Run the migrations to create the tables:

npx drizzle-kit push

Run the server with the following command:

npm run dev

Tests

Run lint:

npm run lint

Run tests:

npm run test

In order to run the integration test, you need to start the test server:

npm run dev:test

Then you can run the integration tests:

npm run test:integration

Docker

To run the application using Docker:

docker build  --platform linux/amd64  -t todo-api .
docker run -p 4000:4000 todo-api

Queries implemented:

You might need to create the user in the database in order to test it below:

Sign In:

curl --location 'http://localhost:4000/graphql' \
--header 'Content-Type: application/json' \
--data '{"query":"mutation signIn($input: SignInDAO!) {\n  signIn(input: $input) {\n    accessToken\n  }\n}","variables":{"input":{"username":"username","password":"password"}}}'

Create Task:

curl --location 'http://localhost:4000/graphql' \
--header 'Authorization: Bearer ACCESS_TOKEN' \
--header 'Content-Type: application/json' \
--data '{"query":"mutation($input: CreateTaskDAO!) {\n  createTask(input: $input) {\n    id\n    title\n    description\n    status\n  }\n}","variables":{"input":{"title":"Task 1","description":"Some random description","status":"todo"}}}'

Update Task:

curl --location 'http://localhost:4000/graphql' \
--header 'Authorization: Bearer ACCESS_TOKEN' \
--header 'Content-Type: application/json' \
--data '{"query":"mutation($updateTaskId: ID!, $input: UpdateTaskDAO!) {\n  updateTask(id: $updateTaskId, input: $input) {\n    id\n    title\n    description\n    status\n  }\n}","variables":{"updateTaskId":1,"input":{"status":"inProgress"}}}'

List of Tasks:

curl --location 'http://localhost:4000/graphql' \
--header 'Authorization: Bearer ACCESS_TOKEN' \
--header 'Content-Type: application/json' \
--data '{"query":"query {\n  tasks {\n    totalCount\n    items {\n      id\n      title\n      description\n      status\n    }\n  }\n}","variables":{}}'

TODO

  1. Host
  2. CI to run integration tests
  3. Improve local development with DB Seed

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •