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.
- Get your information from the both previous queries ready (list of repositories, and your issue’s
id
). -
Create a mutation by either typing or pasting the following into the GraphQL explorer.
mutation AddComment { addComment(input: { subjectId: "[issueID]", body: "[contribution template]"}) { subject { id } } }
Look around using the built in documentation. By hovering, erasing, retyping, or changing fields, what can you learn about this mutation?
- Change
[issueID]
to the issueid
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. - Click the “Execute Query” button
- Go to your issue and find your posted comment.
- 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.