There are many implementations of data loaders available for sql language in go. But how can i implement dataloader functionality in golang using mongodb. I am using gqlgen library for my graphql code.
I want to fetch all the products with their category. I want to cashe the information of category.
My graphql query looks like :
query example {
products: GetProducts{
Id,
Name,
Description,
Price,
Quantity,
Category {
Id,
Name
}
},
}
For above query if there are 1000 products and 10 categories then i will query 1000 times for only 10 categories. Hence I want to cashe it.
My Mongodb Products Schema :
{
"_id": {
"$oid": "663c6371bd05f26997e9d528"
},
"name": "Gulab Jamun",
"description": "this is a product",
"price": 210.45,
"quantity": 10,
"category": "663b89711f437c9bcf6d3864"
}
My Mongodb Categories Schema :
{
"_id": {
"$oid": "663b896d1f437c9bcf6d3863"
},
"name": "electronics"
}