Skip to content

Signup, Login, and Book CRUD API using Node.js, Apollo Server, GraphQL, JWT Authentication, and Mongoose.

Notifications You must be signed in to change notification settings

SuvojitDev/graphQLAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📁 GraphQL API — All in One Postman Guide


🔹 Tech Stack

  • Node.js
  • Apollo Server
  • GraphQL
  • JWT Authentication
  • Mongoose/Mongodb

🔹 Environment Variables

Create a .env file in your root directory:

SECRET_KEY=your_secret_key
DB_URI=mongodb+srv://yourUsername:yourPass@yourCluster.example/test
PORT=4000

🔹 Installation

git clone <your-repo-url>
cd your-repo
npm install

🔹 Run the Application

    npm start

🔹 Auth Notes

  • Signup and login are public
  • All other operations require Authorization:Bearer YOUR-JWT-TOKEN

🔹 API Operations

🔹 Signup (POST)

  • 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" }
}

🔹 Login (POST)

{
  "query": "mutation ($username: String!, $password: String!) { login(username: $username, password: $password) { token message } }",
  "variables": { "username": "foo", "password": "123123" }
}

🔹 Add Book (POST)

{
  "query": "mutation ($title: String!, $author: String!) { addBook(title: $title, author: $author) { id title author } }",
  "variables": { "title": "New Title", "author": "Author Name" }
}

🔹 Get All Books (POST)

{
  "query": "query { books { id title author } }"
}

🔹 Get Book by ID (POST)

{
  "query": "query ($id: ID!) { book(id: $id) { id title author } }",
  "variables": { "id": "<your-book-id>" }
}

🔹 Update Book (POST)

{
  "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" }
}

🔹 Delete Book (POST)

{
  "query": "mutation ($id: ID!) { deleteBook(id: $id) { message } }",
  "variables": { "id": "<your-book-id>" }
}

About

Signup, Login, and Book CRUD API using Node.js, Apollo Server, GraphQL, JWT Authentication, and Mongoose.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published