A boilerplate of a nodejs server, written in Typescript, with JWT authentication, GraphQL and TypeORM
- Compile the ts files.
npm test
docker-compose build
docker-compose up
There are two endpoints, /sign and /api.
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 protected]",
"password": "password"
},
"newUser": {
"name": "user",
"profile": {
"email": "[email protected]"
},
"password": "password"
}
}
Result Login:
{
"data": {
"signIn": {
"result": true,
"token": "******",
"error": null,
"info": {
"message": "Logged In Successfully"
}
}
}
}
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 protected]"
}
Result:
{
"data": {
"getByEmail": {
"name": "user"
}
}
}
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"
- 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/