'How to use graphql-request's batching via the batchRequests() function in redux-saga?
I'm trying to implement batching in redux-saga using graphql-request's batchRequests() function but not sure of the syntax.
Here's what I've tried
export default ({ gqlClient } = {}) => {
function* getDashboardData() {
while (true) {
try {
yield take(dashboardActions.getDashboardDataPending.type);
yield call([gqlClient, gqlClient.batchRequests],
{ document: queries.home.getUserData, variables: { period: 'day', date: 'last30' } },
{ document: queries.home.getRevenueData, variables: { period: 'day', date: 'last60' } }
);
...
}
}
}
}
export default ({ gqlClient } = {}) => {
function* getDashboardData() {
while (true) {
try {
yield take(dashboardActions.getDashboardDataPending.type);
yield apply(gqlClient, gqlClient.batchRequests,
[
{ document: queries.home.getUserData, variables: { period: 'day', date: 'last30' } },
{ document: queries.home.getRevenueData, variables: { period: 'day', date: 'last60' } }
]);
...
}
}
}
}
But this doesn't work. Error screenshot Using graphql-request v3.7.0 & redux-saga v1.1.3
Can someone tell the correct way to do it? graphql-request's docs
Solution 1:[1]
This worked for me
export default ({ gqlClient } = {}) => {
function* getDashboardData() {
while (true) {
try {
yield take(dashboardActions.getDashboardDataPending.type);
yield call([gqlClient, gqlClient.batchRequests],
[{ document: queries.home.getUserData, variables: { period: 'day', date: 'last30' } },
{ document: queries.home.getRevenueData, variables: { period: 'day', date: 'last60' } }]
);
...
}
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Rishav |
