This repository contains a simple GraphQL-based recipe app built with Node.js, Appolo, and MongoDB. The app provides a GraphQL API for managing recipes and reviews. This mini project is just for practicing your graphql skills.
The Recipe model represents a recipe with the following properties:
id(ID): Unique identifier for the recipe.title(String): Title of the recipe.description(String): Description of the recipe.difficulty(String): Difficulty level, with options ["Easy", "Medium", "Hard"] (default: "Medium").createdAt(String): Timestamp when the recipe was created.reviews(Array of Review IDs): Array containing IDs of reviews associated with the recipe.
The Review model represents a review with the following properties:
id(ID): Unique identifier for the review.rating(Float): Rating given for the recipe (min: 1, max: 5).comment(String): Comment provided in the review.
The GraphQL schema defines the following types:
- Recipe: Represents a recipe with fields (
id,title,description,difficulty,createdAt,reviews). - Review: Represents a review with fields (
id,rating,comment). - Query: Defines queries to fetch recipes and reviews.
- Mutation: Defines mutations to add, update, and delete recipes and reviews.
Resolvers define the logic for handling GraphQL operations. Key resolvers include:
-
Query Resolvers:
recipes: Fetch all recipes.recipe: Fetch a specific recipe by ID.reviews: Fetch all reviews.review: Fetch a specific review by ID.
-
Mutation Resolvers:
addRecipe: Add a new recipe.addReview: Add a new review.updateRecipe: Update an existing recipe.updateReview: Update an existing review.deleteRecipe: Delete a recipe.deleteReview: Delete a review.
-
Recipe Resolvers:
reviews: Fetch associated reviews for a recipe.
- Clone the repository:
git clone https://github.com/Devai-coding/graphQl-mini-app
cd your-recipe-app
npm install- and here is an example to fill your MongoDB database : Example MongoDB data for reviews:
[{
"_id": {
"$oid": "6548e4eeede863d219973b18"
},
"rating": 4,
"comment": "Great experience! The recipe was amazing."
},
{
"_id": {
"$oid": "6548e515ede863d219973b19"
},
"rating": 5,
"comment": "Nice recipe!!!"
},
{
"_id": {
"$oid": "6548eac7ede863d219973b23"
},
"rating": 4,
"comment": "Not terrible after All!!!"
},
{
"_id": {
"$oid": "6548f4cdff496739bc03faf5"
},
"rating": 5,
"comment": "Perfectoo !!!",
"__v": 0
}]Example MongoDB data for recipes:
[{
"_id": {
"$oid": "6548e607ede863d219973b1e"
},
"title": "Delicious Pasta Recipe",
"description": "A mouth-watering pasta dish that everyone loves!",
"difficulty": "Medium",
"createdAt": "2023-11-06T12:00:00Z",
"reviews": [
{
"$oid": "6548e515ede863d219973b19"
},
{
"$oid": "6548e4eeede863d219973b18"
}
]
},
{
"_id": {
"$oid": "6548eaeaede863d219973b25"
},
"title": "Delicious Pasta Recipe",
"description": "A mouth-watering pasta dish that everyone loves!",
"difficulty": "Medium",
"createdAt": "2023-11-06T12:00:00Z",
"reviews": [
{
"$oid": "6548ea9fede863d219973b22"
},
{
"$oid": "6548eac7ede863d219973b23"
}
]
},
{
"_id": {
"$oid": "6548f3b94cfed4d0f9f4f081"
},
"title": "updated Recipe",
"description": "This is the full desc of this recipe",
"difficulty": "Hard",
"reviews": [
{
"$oid": "6548f4cdff496739bc03faf5"
},
{
"$oid": "6548eac7ede863d219973b23"
}
],
"createdAt": {
"$date": "2023-11-06T14:10:01.213Z"
},
"__v": 0
}]- Run the Server Start the GraphQL server:
npm startThe server will be available at http://localhost:4000 and you can test your projects with the Apollo Sandbox tool.
Feel free to write your own solutions or to contribute additional questions, solutions, or improvements to existing content.


