This project demonstrates the implementation of CRUD (Create, Read, Update, Delete) operations for managing users and products using TypeScript, Node.js, and GraphQL. The application uses MongoDB as the database and Apollo Server for handling GraphQL queries and mutations.
-
User Management:
- Create a new user
- Retrieve all users
- Update user details
- Delete a user
-
Product Management:
- Create a new product
- Retrieve all
- Update product details
- Delete a
- Node.js: Backend runtime environment
- TypeScript: Type-safe JavaScript
- GraphQL: API query language
- Apollo Server: GraphQL server
- MongoDB: NoSQL database
- Mongoose: ODM for MongoDB
- Clone The Repo
git clone https://github.com/EmanSaeed331/GraphQL-nodejs.git
cd GraphQL-nodejs
2.Install dependencies:
npm install
3.Set up environment variables: Create a .env file in the root directory and add the following:
PORT=3000
MONGO_URI=your_mongodb_connection_string
4.Start the development server:
npm run dev
After starting the server, you can access the GraphQL playground at:
http://localhost:3000/graphql
- Get All Users :
query { users { success total users { id username email } } }
- Create User
mutation { regUser(username: "Test", email: "[email protected]", password: "passTest") { id username email } }
- Update User
mutation { updateUser(id: "<USER_ID>", username: "JaneDoe") { id username email } }
- Delete User
mutation { deleteUser(id: "<USER_ID>") { success message id } }
- Get All Products :
query { products { success total products { id name price } } }
-
Create Product
mutation { addProduct(name: "Laptop", price: 1200) { id name price } }
-
Update Product
mutation { updateProduct(id: "<PRODUCT_ID>", name: "Gaming Laptop") { id name price } }
-
Delete Product
mutation { deleteProduct(id: "<PRODUCT_ID>") { success message id } }
Feel free to fork this repository and submit pull requests with improvements or bug fixes.