This app allows you to search for new books, create a list of searched books to purchase.
Setting up an Apollo Server to use GraphQL queries and mutations to fetch and modify data, replacing the existing RESTful API.
Modifying the existing authentication middleware so that it works in the context of a GraphQL API.
Creating an Apollo Provider so that requests can communicate with an Apollo Server.
Deploying your application to Heroku with a MongoDB database using MongoDB Atlas.
https://aqueous-taiga-47604.herokuapp.com/
npm install
keep separate terminals for all
mongod
cd client > npm run build//for production
npm run deploy
In case you want to seed the data as well : node seed/seed.js
(refer to scripts in package.json) scripts should look like this :
"start": "node server/server.js",
"develop": "concurrently \"cd server && npm run watch\" \"cd client && npm start\"",
"install": "cd server && npm i && cd ../client && npm i",
"build": "cd client && npm run build"
npx kill-port 3000
Mutation (for logging in)
mutation Login($email: String!, $password:String!) {
login(email: $email, password:$password){
user {
email
password
}
}
}
query variable
```md
{
"email": "[email protected]",
"password": "password02"
}
```
Result
{
"data": {
"login": {
"user": {
"email": "[email protected]",
"password": "$2b$10$BN48OB/mtfpSJJ8bVkq7BOB.mMybOAj6hyMd.L/p8I8uRfiu1gLda"
}
}
}
}
#Sign-up mutation
mutation AddUser($username: String!, $email: String!, $password: String!) {
addUser(username:$username,email: $email, password:$password){
user {
username
email
password
}
}
}
query variables
{
"username":"abcd",
"email": "[email protected]",
"password": "12345678"
}
Result
{
"data": {
"addUser": {
"user": {
"username": "abcd",
"email": "[email protected]",
"password": "$2b$10$YhKCqDq66xOudOzjGlUuZu/2yiLv8kcxqfVMOosBYN/PE8adAYmoW"
}
}
}
}
© 2021 Rajni Dua
Licensed under MIT