Skip to content

jeffeloy/contacts-api-graphql

Repository files navigation

📞 Contacts API - GraphQL with Node.js, TypeGraphQL, Apollo Server

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.


🛠️ Technologies Used

  • Node.js
  • TypeScript
  • GraphQL
  • Apollo Server (@apollo/server)
  • TypeGraphQL
  • Prisma (MySQL)
  • Mongoose (MongoDB)
  • JWT (jsonwebtoken)

📦 Installation

  1. Clone the repository:
git clone https://github.com/jeffeloy/contacts-api
cd contacts-api
  1. Create a .env file based on .env.example:
cp .env.example .env
  1. 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

🚀 Running the Project

  1. Execute the project with Docker Compose
docker compose up -d

This will bring up:

The API (Node.js) MySQL MongoDB

  1. Make sure your databases are running:

  2. Access the API GraphQL playground at http://localhost:4000/graphql

🔐 Authentication - Generating JWT Token

Auth Route

POST http://localhost:4000/auth

Request Body

{
  "clientId": "clientId" // Available client IDs are in the ./src/graphql/config/clientConfig.ts file
}

Response Body

{
  "token": "seu-token-jwt-aqui"
}

📚 Usage Example in GraphQL Playground

Authorization: Bearer seu-token-jwt-aqui

➡️ Mutation to add contacts

mutation AddContacts($contacts: [ContactInput!]!) {
  addContacts(contacts: $contacts)
}

Variables

{
  "contacts": [
    {
      "name": "Your Name",
      "phone": "5541999999999"
    }
  ]
}

➡️ Query to list contacts

query GetContacts {
  getContacts {
    id
    name
    cell_phone
  }
}

👨‍💻 Developed by

Jefferson Eloy - LinkedIn - GitHub

About

API GraphQL to receive and save contacts of differences customers

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published