Skip to content

PJBalogun/book_management_app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GraphQL Books API

This is a simple GraphQL API for managing books and authors, built with Node.js, Express, MongoDB, and GraphQL.

Overview

This project allows you to create, read, and manage books and authors. Each book is linked to an author, and you can query data efficiently using GraphQL.

Features

  • Add new authors and books.
  • Query books and authors.
  • Retrieve all books or authors.
  • Get detailed information about a single book or author, including relational data.

Tech Stack

  • Node.js
  • Express
  • MongoDB (with Mongoose)
  • GraphQL

Installation

  1. Clone the repository:
git clone https://github.com/PJBalogun/graphql-book-api
cd graphql-books-api
  1. Install dependencies:
npm install
  1. Create a .env file and add your MongoDB connection string:
MONGODB_URI=<your_mongodb_uri>
  1. Run the development server:
npm run dev

The server will be running at http://localhost:4000/graphql.

Project Structure

.
├── models
│   ├── author.js
│   └── book.js
├── schema
│   └── schema.js
├── app.js
├── package.json
├── .env
└── README.md

GraphQL Schema

BookType

  • id
  • name
  • genre
  • author (relational field)

AuthorType

  • id
  • name
  • age
  • books (list of books by this author)

Example Queries

Get all books:

{
  books {
    name
    genre
    author {
      name
      age
    }
  }
}

Get a book by ID:

{
  book(id: "123") {
    name
    genre
    author {
      name
    }
  }
}

Add a new author:

mutation {
  addAuthor(name: "J.K. Rowling", age: 55) {
    id
    name
  }
}

Add a new book:

mutation {
  addBook(name: "Harry Potter", genre: "Fantasy", authorId: "123") {
    id
    name
  }
}

Resources

This project was created following the Net Ninja GraphQL Crash Course.

License

This project is open-source and available for educational purposes!


🔥 Happy Coding!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors