Book Collection is a sample application which demonstrates the use of GraphQL in the backend and Vue Apollo on the frontend.
Book Collection uses a number of open source projects to work properly:
Alternatively we can signup and use mLab rather than installing MongoDB.
Clone the repo and change the directory to server
. Run the npm intall
or npm i
to install the dependencies.
$ cd server
$ npm install
Run the application, using the following command.
$ node index.js
Visit the MongoDB website to download and install it. On the same website we can find, Compass which is used to manage the mongodb instance.
Note: There are two json files in server/data
folder which we can restore into the database.
Use the following set of commands to install the frontend dependencies.
$ cd client
$ npm install
Run npm run serve
to start the development server and visit the localhost website.
$ npm run serve
List all the books:
query {
books {
name
genre
author {
name
age
}
}
}
List all the authors:
query {
authors {
name
age
books {
name
genre
}
}
}
Get details for a specific book identified by id
parameter:
query {
book(id: ID!) {
name
genre
author {
name
age
}
}
}
Add a new book:
mutation {
addBook(name: String!, genre: String!, authorId: ID!) {
name
genre
}
}
Add a new author:
mutation {
addAuthor(name: String!, age: Int!) {
name
age
}
}