⚠️ This lesson is retired and might contain outdated information.

Use a GraphQL Mutation to Create a Github Issue Comment

Ian Jones
InstructorIan Jones
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 2 years ago

In this lesson, we use OneGraph's Graphiql editor to create a GraphQL mutation. This is how we can create a comment on a GitHub issue through the editor.

Ian Jones: [0:00] Now that we're successfully querying for comments, let's look at how to create our own. Over in OneGraph we'll go to our dashboard, our app, and then the data explorer. We can add a new mutation.

[0:22] We'll hit the check mark. This mutation is going to be GitHub. It's going to be "Add a comment." For our mutation we need to find the subjectId of the thing that we're commenting on. In our case, this is going to be the GitHub issue.

[0:42] I'm going to change this id to 2. I'll run the commentsListQuery, and then the id is right here, so I'll grab this id. I'll paste it in. We need to pass the body, so the last comment was this one. I will just write, "That was a great movie." Then, we'll submit the mutation.

[1:18] Oops, I need to grab the issueId, not the commentId. If we go back here, now when we run it, we'll start our app, and there's our new comment. As you can see, all you need is the subjectId of the issue that we're working with, and the body of the input that you want to put on your comment.

[2:04] We'll need some return value, so instead of clientMutationId, we will take CommentEdge { node { author login }. We'll take the body, the id, the URL in viewerDidAuthor. We'll rename this mutation to newCommentMutation. It will take a body, which is a string, and it's required, and it will take a subjectId, which is also a string, and it's required.

[2:43] Replace that here. Place this here. We need to grab the subjectId of the thing that we're commenting on. I'm going to run the commentsListQuery, and we'll grab this id, because it's the issue that we're commenting on.

[3:05] We're going to add subjectId to our query variables and then we also need a body for this mutation. Body is "This is a comment." Now, we'll run our newCommentMutation being sure to add comments where they are appropriate. There we go, the mutation works.

egghead
egghead
~ 17 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today