Are requests sending to DGS batched in federation?

Sometimes, inside one GraphQL operation from client(no batched queries), I find our apollo gateway will make multiple requests to the same DGS. is these requests to the same DGS batched? If not, how do we turn on the batch?

Bump it since no one answered it.

Hello! I assume you mean you’re using the DGS framework for your individual subgraphs? If so, I believe I can answer this. The short answer is “batching is not possible as you describe, but for a reasonable reason.”

Sometimes, the gateway does need to execute multiple operations on a single subgraph to fully resolve an incoming operation. Consider this incoming query from a client:

query GetAuthorsAndTopBooks {
  allAuthors { # Authors subgraph
    name
  }

  topBooks { # Books subgraph
    title
    author { # Authors subgraph again
      name
    }
  }
}

Assume we have an Authors subgraph and a Books subgraph. The allAuthors field is resolved by Authors, and the topBooks field is resolved by Books. These two fields are siblings, so they don’t depend on each other. The gateway can send individual operations for these two fields in parallel.

But then notice the author field within topBooks. This field is also resolved by the Authors subgraph, but when our execution started, we didn’t know which books we needed to get the authors for yet. We needed to wait for the Books subgraph to return its part of the topBooks query, which started at the same time as allAuthors. Therefore, batching the requests for Query.allAuthors and Book.author isn’t possible due to a data dependency.