Skip to content

A boilerplate of a nodejs server, written in Typescript, with JWT authentication, TypeGraphQL and TypeORM

License

Notifications You must be signed in to change notification settings

mabuonomo/yggdrasil-ts

Repository files navigation

YGGDRASIL

A boilerplate of a nodejs server, written in Typescript, with JWT authentication, GraphQL and TypeORM

Run

First

  • Compile the ts files.

Run tests

npm test

Run in Docker

docker-compose build
docker-compose up

Endpoints

There are two endpoints, /sign and /api.

Registration and Login (without JWT token)

The first, without JWT check validation, allow you to make a registration and a login

http://localhost:3000/sign
query login($loginInput: LoginInput!) {
  signIn(loginInput: $loginInput) {
    result,
    token,
    error,
    info {
      message
    }
  }
}

mutation register($newUser: UserInput!) {
  signUp(newUser: $newUser) {
    name
  }
}
Query variables:
{
  "loginInput": {
    "email": "email@email.it",
    "password": "password"
  },
  "newUser": {
    "name": "user",
    "profile": {
      "email": "email@email.it"
    },
    "password": "password"
  }
}
Result Login:
{
  "data": {
    "signIn": {
      "result": true,
      "token": "******",
      "error": null,
      "info": {
        "message": "Logged In Successfully"
      }
    }
  }
}

API (need a JWT token)

The second endpoint need a JWT token that you can to get from login query.

http://localhost:3000/api
query getByEmail($email: String!) {
  getByEmail(email: $email) {
    name
  }
}
Query variables:
{
  "email": "email@email.it"
}
Result:
{
  "data": {
    "getByEmail": {
      "name": "user"
    }
  }
}

FAQ

How I can test the endpoint /api?

Finally set the header field: "Authorization Bearer your_jwt_token"

Thanks to