Giter Site home page Giter Site logo

laravel-graphql-book-library's Introduction

Laravel GraphQL API for Books

This project is a Laravel GraphQL API for retrieving books from a database. It offers a variety of queries and mutations for adding, searching, updating and deleting the books from the database.

Installation

  1. Clone the repository and install dependencies:
    git clone https://github.com/mourabitiy/laravel-graphql-book-library
    cd laravel-graphql-book-library
    composer install
  2. Generate an app key
    php artisan key:generate
  3. Set up your database credentials in the .env file
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=[YOUR_DB_NAME]
DB_USERNAME=[YOUR_DB_USERNAME]
DB_PASSWORD=[YOUR_DB_PASSWORD]
  1. Run the Server
php artisan serve

Running the tests

  1. Run the database migrations and populate it using faker
php artisan migrate:fresh --seed
  1. To try out the endpoints, you can use a GraphQL client such as Postman, Insomnia or GraphiQL.

Open the client and set the endpoint to http://127.0.0.1:8000/booksApi. Try out some of the available queries and mutations. For example, to Register

query Register($name: String!, $email: String!, $password: String!) {
  Register(name: $name, email: $email, password: $password) {
      id
      name
      email
  }
}

GRAPHQL VARIABLES

{
  "name":"xxxxxxx",
  "email": "[email protected]",
  "password": "xxxxxxxxx"
}

To login

query Login($email: String, $password: String) {
  Login(email: $email, password: $password) {
    id
    name
    accessToken
  }
}

a list of all books:

{
    books {
        id
        title
        author
        language
        category
        page_count
        publisher
        isbn
    }
}

Unique Book by id

{
     book(id: 157) {
        page_count
        publisher
        isbn
    }
}

Books for a specific Author:

{
     books(author: "Daniel") {
        id
        title
        author
        language
        category
        page_count
        publisher
        isbn
    }
}

Books for a specific isbn, language, title, category, :

Same as the Author, just change the Parameter to : isbn, language, title, category.

Create A book:

     mutation{
            createBook(
                title: "The Book of the Dead",
                author: "John Doe",
                language: "English",
                category: "Horror",
                page_count: 200,
                publisher: "John Doe",
                isbn: "1234567890"
            ){
                title
                author
                language
                category
                page_count
                publisher
                isbn
            }
    }

Update A book:

   mutation{
        updateBook(
            id: 55778,
            title: "The Book of the Dead",
            description: "This is a book about the dead",
            author: "John The Writer",
            language: "En",
            category: "Horror",
            page_count: 200,
            publisher: "John Doe",
            isbn: "1234567890"
        ){
            id
            title
            author
            language
            category
            page_count
            publisher
            isbn
        }
}

Delete A book:

    mutation{
        deleteBook(
            id: 55778
        ){
            id
            title
            author
            language
            category
            page_count
            publisher
            isbn
        }
}

Example : Get a Book by Category

image

laravel-graphql-book-library's People

Contributors

mourabitiy avatar dependabot[bot] avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.