Create a Mutation

Using GraphQL to Add an Issue Comment

So far, we’ve only used GraphQL to form queries, or requests for information. Next, we’re going to use the information we’ve gathered to craft a mutation. Simply put, using a mutation we can actually manipulate server-side data.

animated gif of instructions outlined below

  1. Get your information from the both previous queries ready (list of repositories, and your issue’s id).
  2. Create a mutation by either typing or pasting the following into the GraphQL explorer.

     mutation AddComment {
       addComment(input: {
         subjectId: "[issueID]",
         body: "[contribution template]"})
         subject {

    Look around using the built in documentation. By hovering, erasing, retyping, or changing fields, what can you learn about this mutation?

  3. Change [issueID] to the issue id you found in the most recent query, and [contribution template] to the template you completed earlier based on your most recent contributions. You will need to delete the new lines in between the list items in the template for it to process correctly.
  4. Click the “Execute Query” button
  5. Go to your issue and find your posted comment.
  6. For an extra challenge, use GraphQL to add an emoji reaction to your comment!

Done but not Finished

This was just the tip of the iceberg when it comes to using GraphQL to supercharge your interactions with GitHub.

In this course, we used GraphQL to automagically post information about repositories you recently worked on to an issue, but the possibilities of what your future queries can do is limited by your imagination.

So go out there, experiment with some queries, and share them with the Training team at GitHub and other students in an issue on the course repository. Our favorite queries will be added to a document within the repository for all students to view!

Good luck out there and may your queries be responsive.

Stuck? Open an issue in the repository for this class and mention @githubteacher for help from one of the GitHub trainers!