我的目标:我想在GraphQL Playground中执行一个突变。
我的架构如下:
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!
}
我发现了很多例子,如果有的话,这些例子会起作用:
type Mutation {
# Add a new comment
addComment(comment: String!, author: String!, talkId: Long!): Comment
}
但是我不明白如何在GraphQL Playground中即时创建类型为InputComment
的对象。
例如,在最后一种情况下,我可以运行:
mutation {
addComment(
comment: "My great comment"
author: "The great author"
talkId: 123
) {
id
}
}
答案 0 :(得分:1)
type Comment {
id: ID!
comment: String!
author: String!
talkId: Long!
}
# Input type for a new Comment
input InputComment {
comment: String!
author: String!
talkId: Long!
}
type Mutation {
# Add a new comment
addComment(comment: InputComment!): Comment
}
##Then query should be
mutation {
addComment(comment: {comment: "test comment", author: "Sample name", talkId: 123}) {
id,
comment,
author,
talkId
}
}
答案 1 :(得分:0)
mutation {
addComment(comment: {comment: "Cool", author: "Me", talkId: 12}) {
createdOn
id
}
}