I am currently using batching of similar calls on apollo graphql client.
So it sends single call to apollo-server
if same graphql query is fired but with different parameters.
But on graphql server side I want to optimize such that there also a single call goes to resolve all graphql queries at once.
Graphql server makes call to api server but for each single batched call, not to resolve all queries at once.
I have used data-loader
to use batching but it sends single request only.
genUserInfoDataLoader() {
return new DataLoader(async (arr) => {
logger.info(`---> UserInfoDataLoader Making calls for:${JSON.stringify(arr)}`);
const leagueId = arr[0].split(':')[1];
const UserIds = arr.map(a => a.split(':')[0]);
const userInfoMap = await this.post('endpoint/user-info ', {
userIds: UserIds.join(','),
tourId,
});
return UserIds
.map(
userId => (userInfoMap[userId] ? userInfoMap[userId] : [])
);
});
}