Skip to content

pseudogarden/ariel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ariel

💕 graphql backend project

Overview

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.

Project

The application will be a backend book shelf. The user of the shelf can get a book by:

  book {
    title
    author
    description
    publish_date
  }

🔧 Installation

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

Tasks

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

Queries

@ localhost:3000/graphql

Signup

request

mutation {
  signup(username: "fin", email: "[email protected]", password: "password") {
    id
    username
    email
  }
}

response

{
  "data": {
    "signup": {
      "id": 12,
      "username": "dan",
      "email": "[email protected]"
    }
  }
}

Login

request

mutation {
    login(email: "[email protected]", password: "password") {
        user {
            id
            email
            username
        }
    }
}

response

{
    "data": {
        "login": {
            "user": {
                "id": 12,
                "email": "[email protected]",
                "username": "dan"
            }
        }
    }
}

Add Book

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"
            }
        }
    }
}

Current User

this simply feeds you the current logged in user

request

{
    currentUser {
        id
        username
        email
    }
}

response

{
    "data": {
        "currentUser": {
            "id": 12,
            "username": "dan",
            "email": "[email protected]"
        }
    }
}

Get Books

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"
                }
            }
        ]
    }
}

Releases

No releases published

Packages

No packages published