A reliable API built with Node.js, Yoga-GraphQL, PostgreSQL and Prisma for managing home decor-related data. This project provides a variety of queries and mutations for efficient data handling, making it a powerful backend solution for home decor applications.
- GraphQL API for flexible data queries.
- Support for various mutations to manage home decor data.
- Integrated with Prisma for database management.
- Built with TypeScript for type safety and enhanced development experience.
- Node.js
- Yoga-GraphQL
- Prisma
- Type-GraphQL
- TypeScript
- Express.js
- Neon PostgreSQL
-
Clone the repository:
git clone https://github.com/shehroz-sheri/home-decor-backend-server.git cd home-decor-backend-server
-
Install the dependencies:
npm install
-
Set up your environment variables. Create a .env file in the root directory and add your database connection string and other necessary configurations:
DATABASE_URL = your_database_url PORT = your_port_here (default 4000) EMAIL_USER = your_smtp_user_email_here EMAIL_PASS = your_smtp_user_password_here JWT_SECRET = your_jwt_secret_here
-
Run the following command to generate the typegraphQL types from the prisma schema:
npx prisma generate
To start the server, run:
npm run dev
The server will be available at http://localhost:${PORT}, where PORT is defined in your environment variables (default is 4000).
To test the GraphQL API, follow these steps: - Access the GraphQL API: Open your browser and navigate to http://localhost:${PORT}>/graphql. - Using GraphQL Playground: You can use the built-in GraphQL playground to test queries and mutations. Here are some sample queries and mutations you can use:
mutation {
register(userData: {
name: "John Doe"
email: "john.doe@example.com"
password: "securepassword"
}) {
id
name
email
isVerified
}
}
mutation {
login(email: "john.doe@example.com", password: "securepassword")
}
mutation {
resendOtp(email: "john.doe@example.com")
}
mutation {
deleteUserByEmail(email: "john.doe@example.com") {
id
name
email
}
}
mutation {
login(email: "john.doe@example.com", password: "securepassword", otp: "123456")
}
mutation {
updateProfile(email: "john.doe@example.com", userData: {
name: "John Updated"
phone: "9876543210"
address: "456 New St, Anytown, USA"
password: "newpassword123"
},
oldPassword: "securepassword") {
id
name
email
phone
address
isVerified
}
}
mutation {
deleteUserByEmail(email: "john.doe@example.com") {
id
name
email
}
}
mutation {
forgotPassword(email: "user@example.com")
}
This mutation will send an OTP to the specified email. If the email is associated with a user, you will receive a success response:
mutation {
resetPassword(
email: "user@example.com",
otp: "123456", # Replace with the OTP sent to the email
newPassword: "newSecurePassword123"
)
}
query {
categories {
id
name
}
}
mutation {
createCategory(name: "Sofa") {
id
name
}
}
mutation {
deleteCategory(name: "Sofa") {
id
name
}
}
query {
furnitures {
id
title
description
price
category {
id
name
}
}
}
This query will return a list of all furniture items along with their details.
query {
furniture(id: 1) {
id
title
description
price
category {
id
name
}
}
}
Replace "1" with the actual ID of the furniture item you want to fetch.
mutation {
createFurniture(
title: "Sofa",
description: "A comfortable sofa",
price: 299.99,
categoryId: 1
) {
id
title
description
price
category {
id
name
}
}
}
This mutation will create a new furniture item and return the created item.
mutation {
updateFurniture(
id: 1,
title: "Updated Sofa",
price: 259.99
) {
id
title
description
price
category {
id
name
}
}
}
This mutation updates the title and price of the furniture item with the specified ID.
mutation {
deleteFurniture(id: 1) {
id
title
}
}
This mutation deletes the specified furniture item and returns its ID and title.
query {
getUserFavourites(email: "user@example.com") {
id
title
description
price
category {
id
name
}
}
}
Replace "user@example.com" with the actual email of the user whose favourites you want to fetch.
mutation {
addToFavourites(
email: "user@example.com",
furnitureId: 1
) {
id
title
description
price
category {
id
name
}
}
}
This mutation will add the specified furniture item to the user's favourites and return the added item.
mutation {
removeFromFavourites(
email: "user@example.com", # Replace with the actual user's email
furnitureId: 1 # Replace with the actual furniture ID
)
}
This mutation will remove the specified furniture item from the user's favourites and return true upon success.
query {
getReviewsByFurnitureId(furnitureId: 1) {
id
rating
content
user {
id
email
}
}
}
Replace "1" with the actual ID of the furniture item you want to fetch reviews for.
mutation {
addReview(
furnitureId: 1, # Replace with the actual furniture ID
userId: 1, # Replace with the actual user ID
rating: 5, # Rating should be between 1 and 5
content: "This furniture is excellent!" # Review content
) {
id
rating
content
user {
id
email
}
}
}
This mutation will add a new review for the specified furniture item and return the added review.
mutation {
updateReview(
reviewId: 1, # Replace with the actual review ID
rating: 4, # Updated rating, optional
content: "Updated content for the review." # Updated content, optional
) {
id
rating
content
user {
id
email
}
}
}
This mutation will update the specified review and return the updated review.
mutation {
deleteReview(reviewId: 1) {
id
}
}
This mutation will delete the specified review and return the ID of the deleted review.
query {
getCartByUserId(userId: 1) {
id
userId
items {
id
quantity
furniture {
id
title
price
}
}
}
}
Replace "1" with the actual user ID to fetch the user's cart details.
mutation {
addItemToCart(
userId: 1, # Replace with the actual user ID
furnitureId: 1, # Replace with the actual furniture ID
quantity: 2 # Quantity of the item to add, defaults to 1
) {
id
quantity
furniture {
id
title
price
}
}
}
This mutation will add a new item to the specified user's cart and return the added item details.
mutation {
updateCartItemQuantity(
cartItemId: 1, # Replace with the actual cart item ID
quantity: 3 # New quantity to set
) {
id
quantity
furniture {
id
title
}
}
}
This mutation will update the quantity of the specified cart item and return the updated item details.
mutation {
removeItemFromCart(cartItemId: 1)
}
This mutation will remove the specified item from the cart.
mutation {
clearCart(userId: 1)
}
This mutation will clear all items from the user's cart.
query {
orders {
id
user {
id
name
}
totalPrice
items {
id
furnitureId
quantity
price
}
status
}
}
This query retrieves a list of all orders along with user details, total price, items in each order, and their statuses.
mutation {
createOrder(
userId: 1, # Replace with the actual user ID
items: [
{ furnitureId: 1, price: 100, quantity: 2 }, # Replace with actual furniture ID, price, and quantity
{ furnitureId: 2, price: 50, quantity: 1 } # Replace with actual furniture ID, price, and quantity
],
totalPrice: 250 # Total price of the order
) {
id
totalPrice
items {
id
furnitureId
quantity
price
}
status
}
}
This mutation will create a new order for the specified user and return the details of the created order.
mutation {
updateOrderStatus(
orderId: 1, # Replace with the actual order ID
status: DELIVERED # Replace with the desired status (e.g., "PENDING", "COMPLETED", "CANCELLED", etc.)
) {
id
status
user {
id
name
}
items {
id
furnitureId
quantity
}
}
}
This mutation will update the status of the specified order and return the updated order details.
Contributions are welcome! Please feel free to submit a pull request or open an issue if you have suggestions or improvements.