Skip to content

A Node.js-based GraphQL API for managing products, built with Apollo Server, MongoDB, and Mongoose. Perform CRUD operations efficiently with GraphQL queries and mutations.

Notifications You must be signed in to change notification settings

solarluiso/graphql-products-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GraphQL Products API

A Node.js GraphQL API for managing products. This project allows users to perform CRUD operations on a MongoDB database using GraphQL.

Table of Contents

Features

  • CRUD functionality for products (Create, Read, Update, Delete).
  • GraphQL queries and mutations for managing product data.
  • MongoDB integration with Mongoose.
  • Built with Apollo Server and GraphQL.

Getting Started

Prerequisites

Ensure you have the following installed:

Installation

  1. Clone the repository:

    git clone https://github.com/solarluiso/graphql-products-api.git
    cd graphql-products-api
  2. Install dependencies:

    npm install
  3. Create a .env file in the root directory and add the following environment variables:

    MONGO_URI=your_mongodb_connection_string
    PORT=4000

Usage

Running the Server

Start the server in development mode with hot-reloading:

npm run dev

Or, start the server in production mode:

npm start

The server will run at http://localhost:4000.

API Endpoints

This API uses GraphQL. Use /graphql to query and mutate data. Below are some examples:

Queries

  • Get all products:

    query {
      products {
        id
        title
        category
        price
        inStock
      }
    }
  • Get a single product by ID:

    query {
      product(id: "1") {
        title
        category
        price
      }
    }

Mutations

  • Create a product:

    mutation {
      createProduct(
        title: "Laptop"
        category: "Electronics"
        price: 999.99
        inStock: true
      ) {
        id
        title
      }
    }
  • Update a product:

    mutation {
      updateProduct(id: "1", price: 799.99) {
        id
        title
        price
      }
    }
  • Delete a product:

    mutation {
      deleteProduct(id: "1")
    }

Project Structure

  • src/models: Contains the Mongoose schemas.
  • src/resolvers: Includes GraphQL resolvers for handling queries and mutations.
  • src/schema: Defines the GraphQL schema.
  • src/server.js: Entry point for the application.

Dependencies

Contributing

Contributions are welcome! Feel free to submit a pull request or open an issue.

License

This project is licensed under the ISC License.

About

A Node.js-based GraphQL API for managing products, built with Apollo Server, MongoDB, and Mongoose. Perform CRUD operations efficiently with GraphQL queries and mutations.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published