Integrate multiple Rest APIs with GraphQl and reduce your api calls.
Consider you have these 3 APIs.
Now to fetch the supplier name of an order id. You would perform following steps.
- Get Order details from getOrderById.
- Get Product details form getProductById using the productId received from step 1.
- Get Supplier details from getSupplierById using the supplierId received form step 2.
But if you integrate your APIs with GraphQL. All you need to do is send the following graphql request.
query{
getOrderById(id: $orderId){
date
product{
name
supplier{
name
}
}
}
}
And this will give you a response like -
{
"getOrderById": {
"date": "10-12-2021",
"product": {
"name": "PS5",
"supplier": {
"name": "Sony"
}
}
}
}