Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I execute mutation in GraphQL playground?

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
  }
}
like image 342
B. Wasnie Avatar asked Aug 17 '19 00:08

B. Wasnie


People also ask

How do you pass arguments in GraphQL playground?

To specify that argument, we need to pass in a JSON object containing a value for username . We can do that in GraphQL Playground via the variables tab in the bottom left of the application.


1 Answers

mutation {
  addComment(comment: {comment: "Cool", author: "Me", talkId: 12}) {
    createdOn
    id
  }
}
like image 59
B. Wasnie Avatar answered Oct 18 '22 08:10

B. Wasnie