Built with:
- TypeScript
- MongoDB
- Docker
- GraphQL
Libraries:
- Apollo server ( on express )
- GraphQL ( with tools )
- JsonWebToken
- Inversify
- SonarTS
Principles:
- Feature based code organization
- e2e testing
- unit testing
- Custom JWT authentication with hashed passwords stored in DB.
- Based on dependency injection principles.
We used Insomnia tool for testing GraphQL API responses: https://insomnia.rest/
# install local dependencies
npm install
# create docker containers for development
docker-compose -f docker-compose.yml -f docker-compose.local.yml up -d
# end to end tests
npm run e2e
# unit tests
npm run test
Mutations:
# Create user in DB
mutation {
createUser(username: "unique", password: "pass123",
first_name: "Marc", last_name: "Marcovski")
# Authentication
loginUser(username: "unique",
password: "pass123")
} # copy token which you get in Bearer authorization
# create user for later follow
mutation {
createUser(username: "unique 1", password: "pass123",
first_name: "Boris", last_name: "Yurinov")
}
# Create Board
mutation {
createBoard(
name: "Unique Name",
description: "Board description") {
_id name created_at creator { username first_name }
}
} # copy _id which you get
# Create Pin
mutation {
createPin(board: "boardID",
name: "Unique name",
note: "Note for this pin") {
name created_at board { created_at description name}
creator { username first_name }
}
}
# get all users
{
getAllUsers { _id first_name last_name }
} # copy some _id
# Follow user and Board
mutation {
followBoard(_id: "boardID") {
_id name followers { first_name last_name }
}
followUser(_id: "userID") {
first_name last_name following { first_name last_name }
}
}
Queries:
# Get
fragment userResult on User { username first_name last_name }
fragment boardResult on Board {
name
creator { ...userResult }
followers {...userResult} }
fragment pinResult on Pin {
name created_at note
board { ...boardResult }
creator { ...userResult }
}
{
getPin(_id: "pinID") { ...pinResult }
getBoard(_id: "boardID") { ...boardResult }
getUser { ...userResult }
getUserBoards { ...boardResult }
getUserPins { ...pinResult }
getPinsFromBoard(boardID: "boardID" ) { ...pinResult }
getUserFollowings { ...userResult }
}
To reflect subscription:
- Send one of requests
getAllPins {
name
}
getAllUsers {
username
}
- Go to localhost
docker-compose up -d
Constants GRAPHQL_MIDDLEWARE method .replace(middleware) change middleware which will be executed. Async function changeSchema() from helper.functions is beta version of ExpressGraphQL middleware
GRAPHQL_MIDDLEWARE.haldler() will add middleware on desired endpoint.
|