GraphQL
Create
mutation CreateBook {
createBook(input: {
title: "The Great Gatsby",
author: "F. Scott Fitzgerald",
publishedYear: 1925,
genre: "Classic",
isbn: "9780743273565"
}) {
id
title
author
}
}
Response
{
"data": {
"createBook": {
"id": "101",
"title": "The Great Gatsby",
"author": "F. Scott Fitzgerald"
}
}
}
Read
query GetAllBooks {
books {
id
title
author
publishedYear
genre
}
}
Response
{
"data": {
"books": [
{
"id": "101",
"title": "The Great Gatsby",
"author": "F. Scott Fitzgerald",
"publishedYear": 1925,
"genre": "Classic"
},
{
"id": "102",
"title": "The Catcher in the Rye",
"author": "J. D. Salinger",
"publishedYear": 1951,
"genre": "Classic"
}
]
}
}
query GetBook {
book(id: "123") {
id
title
author
publishedYear
genre
isbn
}
}
Response
{
"data": {
"book": {
"id": "123",
"title": "The Great Gatsby",
"author": "F. Scott Fitzgerald",
"publishedYear": 1925,
"genre": "Classic",
"isbn": "9780743273565"
}
}
}
Update
mutation UpdateBook {
updateBook(id: "123", input: {
title: "The Great Gatsby (Special Edition)",
genre: "Literary Classic"
}) {
id
title
genre
}
}
Response
{
"data": {
"updateBook": {
"id": "123",
"title": "The Great Gatsby (Special Edition)",
"genre": "Literary Classic"
}
}
}
Delete
mutation DeleteBook {
deleteBook(id: "123") {
id
title
}
}
Response
{
"data": {
"deleteBook": {
"id": "123",
"title": "The Great Gatsby (Special Edition)"
}
}
}
Search
Only supports paramter q
for now.
query SearchBooks {
books(q: "Gatsby") {
id
title
author
}
}
Response
{
"data": {
"books": [
{
"id": "101",
"title": "The Great Gatsby",
"author": "F. Scott Fitzgerald"
},
{
"id": "102",
"title": "The Waste Gatsby",
"author": "J. D. Salinger"
}
]
}
}
Pagination
Only supports page
and perPage
for now.
query GetBooks {
books(page: 1, perPage: 10) {
id
title
author
}
}
Response
{
"data": {
"books": [
{
"id": "101",
"title": "The Great Gatsby",
"author": "F. Scott Fitzgerald"
},
{
"id": "102",
"title": "The Catcher in the Rye",
"author": "J. D. Salinger"
}
]
}
}
Filtering
query GetBooks {
books(filters: {
genre: "Classic",
author: "F. Scott Fitzgerald"
}) {
id
title
author
genre
}
}
Response
{
"data": {
"books": [
{
"id": "101",
"title": "The Great Gatsby",
"author": "F. Scott Fitzgerald",
"genre": "Classic"
}
]
}
}