Create a web api for e-commerce platform.
Please design a web API that models the following simple relationship:
Shops have many Products Shops have many Orders Products have many Line Items Orders have many Line Items
Line items refer to any service or product added to an order, along with any quantities, rates, and prices that pertain to them.
For example, if you buy a carton of milk and a loaf of bread at the grocery store, your bill (the representation of your order) will have two line items on it. One for the carton of milk, and the other for the loaf of bread.
Requirements for each object type
Products, Line Items and Orders all need a dollar value The value of a Line Item should map to the value of the Product that the Line Item represents The total value of an Order should equal the sum of the values of all of its Line Items
All of the functionality of your API should be documented so we know what it does, and how to interact with it.
When using your API, there should be at least one shop, one product, one line item, and one order to query. Feel free to commit your data file, include a seed file to populate the db or find some other way to make sure that the app we’ll be testing has data in it.
Requirements:
- NodeJs installed with lastest release and ReactJs version 16+
- First run "npm install" to install the node packages
- To execute the application have two windows open
- First execute "npm run json:server" on first window and execute "npm run start"
- Graphql server is located on "https://localhost:4000/graphql"
Takes a id parameter and return the following:
- id : ID
- name : String
- location : String
- country : String
- products : Products
- orders : Order
{
store(id: "abc123"){
id
name
location
country
products{
id
name
description
}
orders{
id
date
description
payment
}
}
}
Take no parameters and return all the stores
{
stores{
id
name
location
country
products{
id
name
description
}
orders{
id
date
description
payment
}
}
}
Takes a id parameter and return the following:
- id : ID
- name : String
- description : String
- store : Store
- lineItems : lineItem
{
product(id: "abc123"){
id
name
description
store{
id
name
location
country
}
lineItems{
id
quantity
price
delivery
}
}
}
Take no parameters and return all the products
{
products{
id
name
description
store{
id
name
location
country
}
lineItems{
id
quantity
price
delivery
}
}
}
Takes a id parameter and return the following:
- id : ID
- date : String
- address : String
- description : String
- payment : String
- store : Store
- lineItems : lineItem
{
store(id: "abc123"){
id
date
address
description
payment
store{
id
name
location
country
}
lineItems{
id
quantity
price
delivery
}
}
}
Take no parameters and return all the orders
{
orders{
id
date
address
description
payment
store{
id
name
location
country
}
lineItems{
id
quantity
price
delivery
}
}
}
Takes a id parameter and return the following:
- id : ID
- quantity : Int
- price : Int
- delivery : String
- product : Product
- order : Order
{
lineItem(id: "abc123"){
id
quantity
price
delivery
product{
id
name
description
}
order{
id
date
address
description
payment
}
}
}
Take no parameters and return all the orders
{
lineItems{
id
quantity
price
delivery
product{
id
name
description
}
order{
id
date
address
description
payment
}
}
}
Takes three parameters and cannot be empty before creating a store object
{
createStore(name: "Fakeshop", location: "Fakeplace", country:"Fakecountry"){
id
name
location
country
}
}
Takes ID parameters and three optional parameters, then updates from the input given by the optional parameter
{
createStore(id:"123456", name: "Fakeshop", location: "Fakeplace", country:"Fakecountry"){
id
name
location
country
}
}
Takes ID parameter and removes from the database { deleteStore(id: "122345"){ id name location country } } }
Takes three parameters and cannot be empty before creating a product object
{
addProduct(name: "Fakeshop", description: "Fake description", storeID: "store123"){
id
name
description
}
}
Takes ID parameters and three optional parameters, then updates from the input given by the optional parameter
{
editProduct(id: "product123", name: "Fakeshop", description: "Fake description", storeID: "store123"){
id
name
description
}
}
Takes ID parameter and removes from the database { deleteProduct(id: "122345"){ id name description } } }
Takes five parameters and cannot be empty before creating an order object
{
createStore(date: "01-01-2000", address: "123 Fake Street", description:"Fake description", payment: "visa", "storeId": "123456"){
id
date
address
description
payment
store{
id
name
location
country
}
}
}
editOrder(id: ID!, date: String, address: String, description: String, payment: String, "storeId": ID)
Takes ID parameters and six optional parameters, then updates from the input given by the optional parameter
{
editStore(date: "01-01-2000", address: "123 Fake Street", description:"Fake description", payment: "visa", "storeId": "123456"){
id
date
address
description
payment
store{
id
name
location
country
}
}
}
Takes ID parameter and removes from the database { deleteOrder(id: "122345"){ id date address description payment store{ id name location country } } } }
Takes five parameters and cannot be empty before creating a store object
{
addLineItem(quantity:1, price: 600, delivery:"rush", productId:"pro123", orderId:"ord123"){
quantity
price
delivery
product{
id
name
description
}
order{
id
address
}
}
}
Takes ID parameters and five optional parameters, then updates from the input given by the optional parameter
{
editLineItem(id: ID!, quantity:1, price: 600, delivery:"rush", productId:"pro123", orderId:"ord123"){
quantity
price
delivery
product{
id
name
description
}
order{
id
address
}
}
}
Takes ID parameter and removes from the database { deleteStore(id: "122345"){ quantity price delivery product{ id name description } order{ id address } } }
Project link: https://graphqlapiweb.herokuapp.com/graphql
Features:
- GraphQL explorer is running on port 4000
- MongoDB for storing the data in real time
- Jest test cases has been created to test the CRUD functionality
Note(s):
- To run the testcases, please first update the ID accordingly and then type "npm run test"
- The database should have been seed with data and to verify please check with this query
{
stores{
id
name
location
country
products{
id
name
description
lineItems{
id
quantity
price
delivery
}
}
orders{
id
date
address
description
payment
lineItems{
id
quantity
price
delivery
}
}
}
}