ahmedfaaid / Simple-Recipe-API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Simple Recipe API

A simple recipe api that exposes a graphql endpoint with CRUD features. The project uses Apollo GraphQL server with Node, Express, Mongoose and MongoDB.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

Node.js and MongoDB are required for this project to run. To install Node.js, download the appropriate package for your OS here. Follow instructions to install MongoDB here.

Installing

First clone this repository by running:

git clone https://github.com/ahmedfaaid/Simple-Recipe-API.git

Then install all the necessary dependencies by running:

npm install

Run the server using:

npm start

Open the GraphQL playground at http://localhost:3020/graphql

Create your first recipe

mutation {
  createRecipe(
    recipe: {
      name: "Recipe name..."
      cuisine: "Origin of food..."
      description: "Delicious meal"
      category: "Main dish"
      ingredients: "Many ingredients..."
    },
    image: {...}
  ) {
    _id
    name
    cuisine
    description
    category
    ingredients
    image {
      _id
      filename
      path
      mimetype
    }
  }
}

The best way to run the createRecipe mutation is either using Apollo Client and Apollo Upload Client or using Postman/Insomnia with the example below

create recipe

Operations json should look like:

{
  "query": "mutation CreateRecipe($recipe: RecipeInput!, $image: Upload!) { createRecipe(recipe: $recipe, image: $image) { _id name cuisine description category ingredients image { _id filename path mimetype } } }",
  "variables": {
    "recipe": {
      "name": "Recipe name ...",
      "cuisine": "Origin ...",
      "description": "Recipe description ...",
      "category": "Category ...",
      "ingredients": "Some ingredients"
    },
    "image": null
  },
  "operationName": "CreateRecipe"
}

Query all recipes

query {
  getRecipes {
    _id
    name
    ingredients
  }
}

Query one recipe

query {
  getRecipe(id: "...") {
    _id
    name
    ingredients
  }
}

Other graphql operations available in the schema document.

Built With

License

This project is licensed under the MIT License - see the LICENSE.md file for details

About

License:MIT License


Languages

Language:TypeScript 100.0%