Batching & mutations?

schema-request

#1

How to batch multiple queries? indicates that queries can be batched normally (just put multiple queries in a single query statement), however:

  • is it guaranteed that batched queries will yield coherent results?
  • can mutations can be batched in the same way (put multiple mutations in a single mutation statement) (cf graphql supports)
  • batched mutations should be sequential but is the entire batch atomic aka if one mutation fails, do the following mutations get skipped, and are the preceding mutations rollbacked?

#2

Hi @xmo-odoo,

I think, in the same way that you can batch queries normally (as described in How to batch multiple queries?) you can batch multiple mutations. Here’s an example where I added both a heart and a thumbs up to an issue:

mutation {
  heart: addReaction(input: {subjectId: "MDU6SXNzdWUyOTE2Njk3MjU=", content: HEART}) {
    reaction {
      content
      createdAt
    }
  }
  thumbs_up: addReaction(input: {subjectId: "MDU6SXNzdWUyOTE2Njk3MjU=", content: THUMBS_UP}) {
    reaction {
      content
      createdAt
    }
  }
}

and the result

{
  "data": {
    "heart": {
      "reaction": {
        "content": "HEART",
        "createdAt": "2018-03-27T05:38:08Z"
      }
    },
    "thumbs_up": {
      "reaction": {
        "content": "THUMBS_UP",
        "createdAt": "2018-03-27T05:41:44Z"
      }
    }
  }
}

As far as whether the entire batch is atomic, no, I don’t believe so. I think each mutation will be executed regardless of whether the rest of the mutations have succeeded. Here’s an example where I attempted to add two reactions to a pull request comment and also to delete a pull request review - which I got an error on because it was not pending (you can only delete a pending PR review):

mutation {
  heart: addReaction(input: {subjectId: "MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE3NzMxNDE3MQ==", content: HEART}) {
    reaction {
      content
      createdAt
    }
  }
  delete: deletePullRequestReview(input: {pullRequestReviewId: "MDE3OlB1bGxSZXF1ZXN0UmV2aWV3MTA3MTU5MjEw"}) {
    pullRequestReview {
      author {
        login
      }
    }
  }
  thumbs_up: addReaction(input: {subjectId: "MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE3NzMxNDE3MQ==", content: THUMBS_UP}) {
    reaction {
      content
      createdAt
    }
  }
}

and the response:

{
  "data": {
    "heart": {
      "reaction": {
        "content": "HEART",
        "createdAt": "2018-03-27T05:55:34Z"
      }
    },
    "delete": null,
    "thumbs_up": {
      "reaction": {
        "content": "THUMBS_UP",
        "createdAt": "2018-03-27T05:55:34Z"
      }
    }
  },
  "errors": [
    {
      "message": "Can not delete a non-pending pull request review",
      "type": "FORBIDDEN",
      "path": [
        "delete"
      ],
      "locations": [
        {
          "line": 8,
          "column": 3
        }

as you can see, both reaction mutations worked (evidence is at https://github.com/rlinehan/test/pull/11#discussion_r177314171), despite the delete failing.