I think you have understood this incorrectly. GraphQL and REST are two different protocols. GraphQL does not batch REST calls. What it does is represent data in a tree-like structure, so the clients can request specific information and the server responds with the requested information only, unlike REST APIs where a certain resource is always responding with a pre-defined data model.
For example a REST resource /api/user
always responds with a pre-defined structure like this:
{
"id": 1
"name": "John Doe",
}
Then if you need to retrieve, say, the posts from a user, you have to send a new request to /api/{user_id}/posts
. This is called under-fetching, i.e. You have to send multiple requests to fetch all the data you need since a single request does not send all the data you need.
But in GraphQL this is defined in the GraphQL schema as a single object.
type User {
id: ID!
name: String!
posts: [Post!]!
}
type Post {
id: ID!
title: String!
content: String!
}
In this case, a client can request the information like this:
query {
user {
name
posts {
title
content
}
}
}
This will return a response with the user name and the posts from that user with the post title and the content.
Retrieval of this data depends on the GraphQL server implementation. The advantage is you don't have to send two requests to the server as in a REST API. You can send this request and the GraphQL server responds with the requested data.
In your case, the backend does send two requests to the REST endpoints and batch the data, then sends them back to the client. This reduces the number of API calls from the client. But the backend still has to do two calls to fetch the data from a REST API. The advantage here is that the client does not have to send multiple requests and it does not receive data that it did not request.
Consider a scenario where you retrieve the data from a database in the backend. In this case, actually, you don't need to send multiple requests to the database but retrieve the data in a lesser number of database queries as well.