Correct format for mutation?


I don’t see an example mutation in the GitHub docs. What is the simple mutation supposed to look like in GraphQL?


After some fiddling, this format worked for me:

mutation {
  addComment(input: {
    clientMutationId: "abcd==",
    body: "Test comment",
    subjectId: "abyz="}
  ) {


You can use variables as well, which makes things a bit easier. The single argument (which is why you need to use an input object) is an unfortunate restriction that is not part of GraphQL, but was put in because of Relay. Relay 2 will no longer have that restriction, and Apollo Client already supports the entire GraphQL spec today.


Finding the subjectId was an issue (pardon the pun) for me. I had to query for issues on the repo first, then get the id of the one in question, and then formulate my mutation.

I don’t understand the reasoning behind this. Why would I not be able to get at the issue by its number field? I would think the addComment mutation could just take the repo as another argument in addition to the number, no?

I find the whole edges -> node construction counter-intuitive, or at least difficult to comprehend (especially when the documentation explains none of that).


Yeah, the documentation is definitely lacking in this area. This document from Relay describes a bit more about edges and nodes in the mean time. We’ll be adidng more documentation to make it easier to use soon. :+1:


Yeah, I ran into this too.

Basically, as things stand right now, your mutation needs to select at least 1 field, even if you don’t care about it.

I’m also curious what’s the reason for this restriction. It seems it’d be better if we were allowed to perform a mutation that selects 0 fields.

The restriction makes sense for queries - if you’re selecting 0 fields, it’s a noop, so making it invalid prevents pointless queries from being possible.