https://github.com/saswatamcode/bookgraphql
A simple GraphQL API which stores and queries book and author data using MongoDB.
https://github.com/saswatamcode/bookgraphql
Last synced: 11 months ago
JSON representation
A simple GraphQL API which stores and queries book and author data using MongoDB.
- Host: GitHub
- URL: https://github.com/saswatamcode/bookgraphql
- Owner: saswatamcode
- Created: 2020-03-17T14:22:47.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-12T05:46:49.000Z (about 3 years ago)
- Last Synced: 2025-02-11T08:48:29.827Z (about 1 year ago)
- Language: JavaScript
- Size: 70.3 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://GitHub.com/Naereen/StrapDown.js/graphs/commit-activity)
[](https://GitHub.com/Naereen/ama)
[](https://code.visualstudio.com/)
[](https://GitHub.com/saswatamcode/BookGraphQL/network/)
[](https://GitHub.com/saswatamcode/BookGraphQL/stargazers/)
[](https://GitHub.com/saswatamcode/BookGraphQL/issues/)
[](https://github.com/ellerbrock/open-source-badges/)
[](https://github.com/ellerbrock/javascript-badges/)
# BookGraphQL
A simple GraphQL API which stores and queries book and author data using MongoDB.
## Description
### Mutations
- To add a book into mongodb:
```
mutation {
addBook(name: "The Great Gatsby", genre: "Fiction", authorId: "1"){
name
genre
}
}
```
- To add an author into mongodb:
```
mutation {
addAuthor(name: "F.Scott Fitzgerald", age: 44){
name
age
}
}
```
### Queries
- To query a book
```
{
book(id: "1"){
name
genre
author{
name
age
}
}
}
```
- To query all books
```
{
books{
name
genre
author{
name
age
}
}
}
```
- To query an author
```
{
author(id: "1"){
name
age
books{
name
genre
}
}
}
```
- To query all authors
```
{
authors{
name
age
books{
name
genre
}
}
}
```
## To Run
- Clone into repo
- Run `npm i`
- Run `nodemon app.js`
- Visit `localhost:4000/graphql` to open GraphiQL