- Node.js
- Apollo Server
- GraphQL
- JWT Authentication
- Mongoose/Mongodb
Create a .env
file in your root directory:
SECRET_KEY=your_secret_key
DB_URI=mongodb+srv://yourUsername:yourPass@yourCluster.example/test
PORT=4000
git clone <your-repo-url>
cd your-repo
npm install
npm start
Signup
andlogin
arepublic
- All other operations require Authorization:Bearer YOUR-JWT-TOKEN
- URL:
http://localhost:4000/graphql
- Body (GraphQL):
{
"query": "mutation ($username: String!, $email: String, $password: String!) { signup(username: $username, email: $email, password: $password) { message } }",
"variables": { "username": "foo", "email": "foo@example.com", "password": "123123" }
}
- URL: http://localhost:4000/graphql
- Body (GraphQL):
{
"query": "mutation ($username: String!, $password: String!) { login(username: $username, password: $password) { token message } }",
"variables": { "username": "foo", "password": "123123" }
}
- URL: http://localhost:4000/graphql
- Headers: Authorization: Bearer YOUR-JWT-TOKEN
- Content-Type: application/json
- Body (GraphQL):
{
"query": "mutation ($title: String!, $author: String!) { addBook(title: $title, author: $author) { id title author } }",
"variables": { "title": "New Title", "author": "Author Name" }
}
- URL: http://localhost:4000/graphql
- Headers: Authorization: Bearer YOUR-JWT-TOKEN
- Content-Type: application/json
- Body (GraphQL):
{
"query": "query { books { id title author } }"
}
- URL: http://localhost:4000/graphql
- Headers: Authorization: Bearer YOUR-JWT-TOKEN
- Content-Type: application/json
- Body (GraphQL):
{
"query": "query ($id: ID!) { book(id: $id) { id title author } }",
"variables": { "id": "<your-book-id>" }
}
- URL: http://localhost:4000/graphql
- Headers: Authorization: Bearer YOUR-JWT-TOKEN
- Content-Type: application/json
- Body (GraphQL):
{
"query": "mutation ($id: ID!, $title: String!, $author: String!) { updateBook(id: $id, title: $title, author: $author) { id title author } }",
"variables": { "id": "<your-book-id>", "title": "Updated Title", "author": "Updated Author" }
}
- URL: http://localhost:4000/graphql
- Headers: Authorization: Bearer YOUR-JWT-TOKEN
- Content-Type: application/json
- Body (GraphQL):
{
"query": "mutation ($id: ID!) { deleteBook(id: $id) { message } }",
"variables": { "id": "<your-book-id>" }
}