Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mabuonomo/yggdrasil-ts

A boilerplate of a nodejs server, written in Typescript, with JWT authentication, TypeGraphQL and TypeORM
https://github.com/mabuonomo/yggdrasil-ts

graphql jwt jwt-authentication nodejs server typegraphql typeorm typescript

Last synced: about 2 months ago
JSON representation

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

Awesome Lists containing this project

README

        

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

## Run
### First
* Compile the ts files.

### Run tests
```bash
npm test
```

### Run in Docker
```bash
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
```
```graphql
query login($loginInput: LoginInput!) {
signIn(loginInput: $loginInput) {
result,
token,
error,
info {
message
}
}
}

mutation register($newUser: UserInput!) {
signUp(newUser: $newUser) {
name
}
}
```
```json
Query variables:
{
"loginInput": {
"email": "[email protected]",
"password": "password"
},
"newUser": {
"name": "user",
"profile": {
"email": "[email protected]"
},
"password": "password"
}
}
```
```json
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
```

```graphql
query getByEmail($email: String!) {
getByEmail(email: $email) {
name
}
}
```
```json
Query variables:
{
"email": "[email protected]"
}
```
```json
Result:
{
"data": {
"getByEmail": {
"name": "user"
}
}
}
```

## FAQ
How I can test the endpoint /api?

* If you use a browser you need a Header Modifier extension.

* In alternative you can use Postman (https://www.getpostman.com) or Insomnia (https://insomnia.rest). Insomnia supports natively graphql application (and GraphiQL explorer).

Finally set the header field: "Authorization Bearer _your_jwt_token_"

## Thanks to
* NodeJS https://nodejs.org
* TypeGraphql https://github.com/19majkel94/type-graphql
* TypeOrm https://github.com/typeorm/typeorm
* JWT https://jwt.io/
* GraphQL http://graphql.github.io/