CRUD API built with GraphQL, Node and Mongo for database
- View a single listing
- View most recent listings
- Create listing with
name, address, description, website, email and phone
- Update Listing
- Delete listing
- Seed Database
Open up a browser and visit
https://graphql-crud-mongo.herokuapp.com/graphql
Send any of the following requests via the GraphiQL window:
mutation{
addListing(name:"Bolu Ventures", address: "ajibawo house, ibadan", description:"techie things", website:"http://boluajibawo.xyz", email:"bolu@yahoo.com", phone:"+23457927938"){
_id
name
description
address
}
}
{
"data": {
"addListing": {
"_id": "5a859392b5e4d40014e96591",
"name": "Bolu Ventures",
"description": "techie things",
"address": "ajibawo house, ibadan"
}
}
}
{
recentListings{
name
description
_id
}
}
{
"data": {
"recentListings": [
{
"name": "Bolu Ventures",
"description": "techie things",
"_id": "5a859392b5e4d40014e96591"
},
{
"name": "booking.com",
"description": "largest hotel booking website",
"_id": "5a844e76e65f591b984f6b3c"
},
{
"name": "hotels.ng",
"description": "book hotels in nigeria",
"_id": "5a844e76e65f591b984f6b3b"
},
{
"name": "flutterwave",
"description": "powerful payments apis",
"_id": "5a844e76e65f591b984f6b3a"
},
{
"name": "jumia",
"description": "best online shopping",
"_id": "5a844e76e65f591b984f6b39"
},
{
"name": "andela",
"description": "training world class developers",
"_id": "5a844e76e65f591b984f6b38"
}
]
}
}
{
singleListing(_id:"5a844e76e65f591b984f6b3c"){
_id
name
email
phone
}
}
{
"data": {
"singleListing": [
{
"_id": "5a844e76e65f591b984f6b3c",
"name": "booking.com",
"email": "hello@domain.com",
"phone": "+23412345678"
}
]
}
}
mutation{
updateListing(_id:"5a844e76e65f591b984f6b3c", name:"Black Panther"){
_id,
name
}
}
{
"data": {
"updateListing": {
"_id": "5a844e76e65f591b984f6b3c",
"name": "Black Panther"
}
}
}
mutation{
deleteListing(_id:"5a844e76e65f591b984f6b39"){
name
}
}
{
"data": {
"deleteListing": null
}
}
To create a local copy, run the following in your terminal:
git clone https://github.com/ajibs/graphql-crud.git
Then change into the local directory, run the following in your terminal:
cd graphql-crud
If you don't have Node.js installed, please go ahead and grab it here. This project uses ES6+ features and requires Node version 8.9.4
Yarn is a package manager for Node.js and can be installed from here.
To confirm that you have Node.js installed, run the following in your terminal:
node -v
You should get something like v8.9.4
.
To confirm that you have Yarn installed, run the following in your terminal:
yarn -v
You should get something like 1.3.2
.
You can setup a database on mlab. You should also create a .env
file using .env.sample
as a prototype.
To install all dependencies, run the following in your terminal:
yarn
To kickstart the application, run the following in your terminal:
npm run dev
Open up a browser and visit
http://localhost:5000/graphql
You can send any of the requests previously mentioned above.
You can also seed your database with the following command:
mutation{
seedDatabase{
name
description
}
}
To build and serve the app for production, run the following in your terminal:
npm run build
Then:
npm run start