- E-commerce App powered with GraphQL
- Description
- The Build Process
- Running the code
- Technologies used
This is a backend graphql service that was developed to mimic part features of an E-commerce backend service.
Features in the service perform CRUD operations for:
- Product
- Name
- Description
- Quantity
- Reviews, etc.
- Category
- Name
- Products
- Review
- Title
- Date
- Comment
- Rating, etc
The src folder contains the GraphQL schema, and resolvers for the various root queries available in the schema.
In the following lines below, a brief description will be given for each functionality.
The various schema definition will be explained below:
type Product {
id: ID!
name: String!
description: String!
quantity: Int!
...
category: Category
reviews: [Review!]!
}
type Category {
id: ID!
name: String!
products(filter: ProductsFilterInput): [Product!]!
}
type Review {
id: ID!
date: String!
title: String!
comment: String!
rating: Int!
productId: ID!
}
You can find the query and mutation schema definitions here
The resolvers folder, contains the resolver function handlers for the various schema definitions.
- For the root-field
category
, categoryId is passed as an argument while sending the query. The categoryId is used to get the single category which the product belongs. - For the root-filed
reviews
, productId is retrieved from the parent params, so as get the particular product and return all the product reviews available.
- The root-field
products
, returns all the products contained in a particular category. To get the products, a filtering functionality is applied to all the products to get the products with a particular categoryId. Also, the gotten products can be filtered based on - onSale boolean value - avgRating calculated value This gives the user the leverage of getting necessary data and not overloaded data.
- The
products
root-field returns the all available products, and filters the products based on onSale and avgRating filter arguments provided (optionally), by the user - The
product
root-field returns a single product, based on the productId argument, used to find a single product if available - The
categories
root-field returns all the categories available. - et.c
To run the code, make sure you are using node version >=14.17.0, npm version >=6.14.0
Follow the below steps, to run the code using your terminal
- Cloning the project
$ git clone https://www.github.com/E-Zbox/e-commerce-app.git
- Switch directories
$ cd e-commerce-app
- Installing project dependencies
$ npm install
- Starting the express server
$ npm run dev
or
$ npm start
- Using Postman, navigate to
localhost:<PORT>/graphql
and run the various queries and mutation defined in the schema file
Cheers ๐ฅ you have successfully ran the code ๐๐พ.
Developed using: