Skip to content

If you're looking to enhance your GraphQL skills, this project provides a valuable opportunity for practice. Integrated with Apollo, it offers a streamlined testing environment for a more straightforward experience.

idboussadel/graphQl-mini-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GraphQL Recipe App

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.

Table of Contents

  1. Models

  2. GraphQL

  3. Getting Started

Models

Recipe Model

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.

Review Model

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.

GraphQL

Type Definitions

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

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.

Getting Started

Installation

  1. Clone the repository:
    git clone https://github.com/Devai-coding/graphQl-mini-app
    cd your-recipe-app
    npm install
  1. 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
}]
  1. Run the Server Start the GraphQL server:
npm start

The server will be available at http://localhost:4000 and you can test your projects with the Apollo Sandbox tool.

My tests

image

image

image

addReview

deleteMutation

updateRecipe

updateReview

Feel free to write your own solutions or to contribute additional questions, solutions, or improvements to existing content.

About

If you're looking to enhance your GraphQL skills, this project provides a valuable opportunity for practice. Integrated with Apollo, it offers a streamlined testing environment for a more straightforward experience.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published