Skip to content

Latest commit

 

History

History
236 lines (224 loc) · 3.86 KB

README.md

File metadata and controls

236 lines (224 loc) · 3.86 KB

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: "fin@test.com", password: "password") {
    id
    username
    email
  }
}

response

{
  "data": {
    "signup": {
      "id": 12,
      "username": "dan",
      "email": "dan@test.com"
    }
  }
}

Login

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

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": "dan@test.com"
        }
    }
}

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