Skip to content

rdeeb/graphql_test

Repository files navigation

GraphQL Test

A simple task manager backend built with GraphQL and Node.js.

Setting up the project

Installation

git clone git@github.com:rdeeb/graphql_test.git
npm install

Setup

First we need to have a postgres database running. You can use docker to run a postgres container:

npm run db:dev

We need to add a .env file to the root of the project. You can use the .env.example file as a template. After this we need to create the database and the tables:

npx prisma migrate dev

After that we can seed the database with some data:

npx prisma db seed

Run

To run the server, run the following command:

npm run start

Test

To run the tests, run the following command:

npm run test

GraphQL Playground

To access the GraphQL Playground, go to http://localhost:4000. You can use the following query to get all the tasks:

query {
  tasks {
    id
    name
    description
    status
  }
}

A task can have a status, and can move into a different status, to know about the available statuses and it's possible transitions, you can use the following query:

query {
  taskStatuses {
    id
    name
    toStatuses {
      id
      name
    }
  }
}

In order to retrieve the tasks or create or update a task, you need to be authenticated. To do that, you can use the following mutation:

mutation Login($input: LoginInput!) {
  login(input: $input) {
    token
    user {
      email
      id
    }
  }
}

With the token now you can access the create and update task mutations:

mutation CreateTask($input: CreateTaskInput!) {
  createTask(input: $input) {
    id
    name
    description
  }
}
mutation UpdateTask($updateTaskId: Int!, $input: UpdateTaskInput!) {
  updateTask(id: $updateTaskId, input: $input) {
    id
    name
    description
    status {
      id
      name
      isInitial
    }
    user {
      id
      email
    }
  }
}

About

A test application for a GraphQL server

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published