GraphQL with HotChocolate & Apollo
Serverside: ASP.Net Core API with HotChocolate GraphQL and MongoDB
Clientside: Reactjs with Apollo Client
Getting Started
Clone the repository to your local machine or download project zip file to your local machine.
For running this project you need the following items to Installed on your local machine
Serverside Prerequisites
Dotnet 6 - Framework
MongoDB - DataBase Engine for store data
Clientside Prerequisites
NPM - Package Manager
Serverside Installing
Run the below command to restore, build and run the project
Restore the nuget packages
Buid the project
Run Server Project
Clientside Installing
Run the below command to install dependencies and run project
Install Dependencies
Run Client Project
Deployment
This project is a easy sample for GraphQL in Dotnet with MongoDB and there is no need to Deployed
Authors
Mohsen Asadi - Initial work - MohsenAsadi
License
This project is licensed under the MIT License
Acknowledgments
Storing data in mongoDB
GraphQL Query, Mutation, Subscription Example
Apollo Client
=============== MONGO CLUSTER ===========================
MongoDB cluster minimize
Config Server:
configsvr012 Shards (each a 2 member
PSS replica set): 1 Routers (mongos):
router01๐ Step 1
docker-compose up -d
๐ Step 2
docker-compose exec configsvr01 sh -c "mongosh < /scripts/init-configserver.js"
docker-compose exec shard01-a sh -c "mongosh < /scripts/init-shard01.js"
docker-compose exec shard02-a sh -c "mongosh < /scripts/init-shard02.js"
๐ Step 3
docker-compose exec router01 sh -c "mongosh < /scripts/init-router.js"
๐ Step 4
docker-compose exec router01 mongosh --port 27017
// Enable sharding for database `MyDatabase`
sh.enableSharding("MyDatabase")
// Setup shardingKey for collection `MyCollection`**
db.adminCommand( { shardCollection: "NFTDB.Post", key: { _id: "hashed"} } )
โ๏ธ Done !!!
But before you start inserting data you should verify them first
!!! If you want to add new shard to existed cluster, check more here
๐ Verify ๐
โ
Verify the status of the sharded cluster ๐
docker-compose exec router01 mongosh --port 27017
sh.status()
โ
Verify status of replica set for each shard ๐
docker exec -it shard-01-node-a bash -c "echo 'rs.status()' | mongosh --port 27017"
docker exec -it shard-02-node-a bash -c "echo 'rs.status()' | mongosh --port 27017"
โ
Check database status
docker-compose exec router01 mongosh --port 27017
use MyDatabase
db.stats()
db.MyCollection.getShardDistribution()
๐ More commands
docker exec -it mongo-config-01 bash -c "echo 'rs.status()' | mongosh --port 27017"
docker exec -it shard-01-node-a bash -c "echo 'rs.help()' | mongosh --port 27017"
docker exec -it shard-01-node-a bash -c "echo 'rs.status()' | mongosh --port 27017"
docker exec -it shard-01-node-a bash -c "echo 'rs.printReplicationInfo()' | mongosh --port 27017"
docker exec -it shard-01-node-a bash -c "echo 'rs.printSlaveReplicationInfo()' | mongosh --port 27017"
0 likes ยท 8 views ยท Jul 10, 2024
Contribute to shujaatsiddiqui/GraphQLAndMongoDB development by creating an account on GitHub.