This project is a GraphQL API to manage mobile contacts, where each client stores their data in different databases (MySQL or MongoDB).
Authentication is handled via JWT.
- Node.js
- TypeScript
- GraphQL
- Apollo Server (@apollo/server)
- TypeGraphQL
- Prisma (MySQL)
- Mongoose (MongoDB)
- JWT (jsonwebtoken)
- Clone the repository:
git clone https://github.com/jeffeloy/contacts-api
cd contacts-api- Create a .env file based on .env.example:
cp .env.example .env- Set your environment variables:
SECRET_KEY="your_secret_key"
DATABASE_URL="mysql://root:root@mysql:3306/contacts-db"
MONGO_URI=mongodb://localhost:27017/contacts-db- Execute the project with Docker Compose
docker compose up -dThis will bring up:
The API (Node.js) MySQL MongoDB
-
Make sure your databases are running:
-
Access the API GraphQL playground at http://localhost:4000/graphql
Auth Route
POST http://localhost:4000/authRequest Body
{
"clientId": "clientId" // Available client IDs are in the ./src/graphql/config/clientConfig.ts file
}Response Body
{
"token": "seu-token-jwt-aqui"
}Authorization: Bearer seu-token-jwt-aqui
mutation AddContacts($contacts: [ContactInput!]!) {
addContacts(contacts: $contacts)
}Variables
{
"contacts": [
{
"name": "Your Name",
"phone": "5541999999999"
}
]
}query GetContacts {
getContacts {
id
name
cell_phone
}
}👨💻 Developed by