Booksql
A library for viewing books which includes categories and featured books
It's very simple to get the API up and running. First, create the database (and database user if necessary) and add them to the .env file.
DB_DATABASE=your_db_name
DB_USERNAME=your_db_user
DB_PASSWORD=your_password
Then install, migrate, seed, and run the server:
composer install
php artisan migrate
php artisan serve
First install graphql-playground
composer require mll-lab/laravel-graphql-playground
Visit http://127.0.0.1:8000/graphql-playground on your browser to test the API
Alternatively you can use Postman, Insomnia or GraphQL Playground apps Use this url: http://localhost:8000/graphql
Simply run
composer seed
query {
books {
id
title
author
description
image
link
description
featured
category {
name
}
}
}
query {
books(count: 10 page: 2) {
data {
id
title
author
description
image
link
description
featured
category {
name
}
}
paginatorInfo {
count
currentPage
firstItem
hasMorePages
lastItem
lastPage
perPage
total
}
}
}
query {
books(count: 30, page: 1, orderBy: [{ field: "created_at", order: ASC }]) {
data {
id
title
author
description
image
link
description
featured
category {
name
}
}
paginatorInfo {
count
currentPage
firstItem
hasMorePages
lastItem
lastPage
perPage
total
}
}
}
query {
book(id: 1) {
id
title
author
description
image
link
description
featured
category {
name
}
}
}
query {
categories {
name
}
}
query {
category(id: 1) {
name
}
}
query {
category(id:1) {
id
name
books {
id
image
link
category {
name
}
}
}
}
query {
booksByFeatured(featured: true) {
title
}
}
If you don't want to use directives you can create your own custom resolvers Create it using artisan command
php artisan lighthouse:query searchQuery
Search book by author
query {
searchQuery(search: "Ryan") {
title
}
}
mutation {
createCategory(name: "Heath") {
id
name
}
}
mutation {
updateCategory(id:7, name: "Health") {
id
name
}
}
mutation {
deleteCategory(id:7){
id
name
}
}
mutation {
createBook(
title: "Endgame beats Avatar"
author: "Ryan Wire"
category_id: 3
) {
id
title
}
}
mutation {
updateBook(
id: 31
title: "Endgame"
author: "Ryan Wire"
category_id: 1
) {
id
title
}
}
mutation {
deleteBook(id:31){
id
title
author
}
}
Graphql endpoint - https://booksql-laravel.herokuapp.com/graphql