This project is a GraphQL CRUD API developed using Apollo Server and MongoDB Atlas. It allows you to create, edit, and delete recipes, making it a great stack for projects that need to scale and have sustainable and easy-to-work-with codebases. If you're looking to enhance your backend programming skills, this project serves as an excellent introduction to GraphQL and Apollo Server.
These instructions will help you set up the project and get it running on your local machine for development and testing purposes.
Make sure you have the following installed on your system:
- Node.js: https://nodejs.org/
- npm (Node Package Manager): https://www.npmjs.com/
- MongoDB Atlas account: https://www.mongodb.com/cloud/atlas
- Clone the repository:
git clone https://github.com/Samuel-Adeyeye/GraphQL-API.git
cd GraphQL-API
- Install the dependencies:
yarn add
Before running the project, you need to configure the MongoDB connection. Follow these steps:
- Create a .env file in the root of the project.
- Add your MongoDB Atlas connection string to the .env file:
MONGODB_URI=YOUR_MONGODB_ATLAS_CONNECTION_STRING
Replace YOUR_MONGODB_ATLAS_CONNECTION_STRING with your actual MongoDB Atlas connection string.
To start the Apollo Server and run the API, use the following command:
yarn start
The server will start, and you should see a message like: "Server running at http://localhost:5000/".
The API follows GraphQL conventions. Below are the available queries and mutations:
query { recipes }
: Get all recipes.query { recipe(id: "RECIPE_ID") }
: Get a specific recipe by ID.mutation { createRecipe(input: { name: "Recipe name", description: "Recipe Description" }) }
: Create a new recipe.mutation { updateRecipe(id: "RECIPE_ID", input: { name: "New Recipe name", description: "New Recipe Description" }) }
: Update an existing recipe.mutation { deleteRecipe(id: "RECIPE_ID") }
: Delete a recipe by ID.