💕 graphql backend project
This project focuses on the implementation of graphql on a backend express-mnode server. This project should act as a guide to help others fully implement graphql for server technology.
The application will be a backend book shelf. The user of the shelf can get a book by:
book {
title
author
description
publish_date
}
Clone repo and navigate to project
git clone https://github.com/pseudogarden/ariel.git && cd ariel
Install latest version of node
nvm install
Install dependencies
npm i
Run development server
npm run start:dev
The client side should be able to
- User signup/login
- Get books by user
- Add book to user shelf
- Edit book in user shelf
- Remove a book from user shelf
- Remove books by author from user shelf
@ localhost:3000/graphql
request
mutation {
signup(username: "fin", email: "fin@test.com", password: "password") {
id
username
email
}
}
response
{
"data": {
"signup": {
"id": 12,
"username": "dan",
"email": "dan@test.com"
}
}
}
request
mutation {
login(email: "dan@test.com", password: "password") {
user {
id
email
username
}
}
}
response
{
"data": {
"login": {
"user": {
"id": 12,
"email": "dan@test.com",
"username": "dan"
}
}
}
}
request
mutation {
addBook(
title: "For Whom The Bell Tolls",
author: "Ernest Hemmingway",
description: "A Novel about war in sapin",
publishDate: "1940-10-21"
) {
id
title
author
description
user {
id
username
}
}
}
response
{
"data": {
"addBook": {
"id": 7,
"title": "For Whom The Bell Tolls",
"author": "Ernest Hemmingway",
"description": "A Novel about war in sapin",
"user": {
"id": 12,
"username": "dan"
}
}
}
}
this simply feeds you the current logged in user
request
{
currentUser {
id
username
email
}
}
response
{
"data": {
"currentUser": {
"id": 12,
"username": "dan",
"email": "dan@test.com"
}
}
}
books of logged in user
request
{
getBooks {
id
title
author
description
user {
id
username
}
}
}
response
{
"data": {
"getBooks": [
{
"id": 7,
"title": "For Whom The Bell Tolls",
"author": "Ernest Hemmingway",
"description": "A Novel about war in sapin",
"user": {
"id": 12,
"username": "dan"
}
}
]
}
}
books of any user via username
request
{
getBooks(username: "john") {
id
title
author
description
user {
id
username
}
}
}
response
{
"data": {
"getBooks": [
{
"id": 1,
"title": "On the Origin of Species",
"author": "Charles Darwin",
"description": "Textbook about evolution",
"user": {
"id": 11,
"username": "john"
}
}
]
}
}