如何在GraphQL中执行突变?
我的目标是:在GraphQL中执行一个突变 我的模式如下所示:如何在GraphQL中执行突变?,graphql,prisma-graphql,Graphql,Prisma Graphql,我的目标是:在GraphQL中执行一个突变 我的模式如下所示: 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
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中动态创建InputComment
类型的对象
例如,对于最后一个场景,我可以运行:
mutation {
addComment(
comment: "My great comment"
author: "The great author"
talkId: 123
) {
id
}
}
还要在模式中添加注释类型
当你在上提问时,一定要包括你正在使用的语言和任何框架或库。这使得帮助你变得更容易。我们中的许多人都在使用Apollo服务器和Apollo客户端,但也有一些著名的人实现了Playwood,他们可能有不同的要求,我不知道,但应该包括关于堆栈的更多信息。
mutation {
addComment(comment: {comment: "Cool", author: "Me", talkId: 12}) {
createdOn
id
}
}
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
}
}