contra/graphql-helix

Do you support Batched queries?

orefalo opened this issue · 2 comments

Like multiple graphql query in a single interaction.

Request:

[
  {
    operationName: "AddQuery",
    variables: { x: 1, y: 2 },
    query: "query AddQuery ($x: Int!, $y: Int!) { add(x: $x, y: $y) }",
  },
  {
    operationName: "DoubleQuery",
    variables: { x: 1 },
    query: "query DoubleQuery ($x: Int!) { add(x: $x, y: $x) }",
  },
  {
    operationName: "BadQuery",
    query: "query DoubleQuery ($x: Int!) {---", // Malformed Query
  },
];

Response:

[
  {
    data: { add: 3 },
  },
  {
    data: { add: 2 },
  },
  {
    errors: [{ message: "Bad Request" }],
  },
];

GraphQL Helix by design does not support this functionality out of the box because it is non-standard behavior and there are different ways of implementing it (for example, do you share context between all three operations or not, do you run in the operations sequentially or in parallel, etc.). However, the library is flexible enough to allow you to add this functionality if you need it. You would effectively just need to check if the body of the request is an array and call processRequest for each operation.

makes sense, thank you