How can I execute mutation in GraphQL playground?

B. Wasnie picture B. Wasnie · Aug 17, 2019 · Viewed 11.1k times · Source

My Goal: I want to execute a mutation in GraphQL Playground.

My schema looks the following:

type Mutation {
    # Add a new comment
    addComment(comment: InputComment!): Comment
}

# Input type for a new Comment
input InputComment {
    # The comment text
    comment: String!
    # The id of the author
    author: String!
    # The id of the talk
    talkId: Long!
}

I found a lot of examples that will work if I have:

type Mutation {
    # Add a new comment
    addComment(comment: String!, author: String!, talkId: Long!): Comment
}

But I can't understand how I can create an object of type InputComment on the fly in GraphQL Playground.

E.g., for the last scenario I could just run:

mutation {
  addComment(
    comment: "My great comment"
    author: "The great author"
    talkId: 123
  ) {
    id
  }
}

Answer

B. Wasnie picture B. Wasnie · Aug 17, 2019
mutation {
  addComment(comment: {comment: "Cool", author: "Me", talkId: 12}) {
    createdOn
    id
  }
}