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
}
}
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.
mutation {
addComment(comment: {comment: "Cool", author: "Me", talkId: 12}) {
createdOn
id
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With