【发布时间】:2019-04-24 14:35:16
【问题描述】:
我正在尝试了解 graphql 的查询和变异语法。给定这个例子:
type Author {
id: Int!
firstName: String
lastName: String
posts: [Post]
}
type Post {
id: Int!
title: String
author: Author
votes: Int
}
type Query {
posts: [Post]
author(id: Int!): Author
}
将帖子与作者相关联的查询应该是什么样的?这是连接发挥作用的地方还是别的什么?这是我试图解决问题但有效的尝试。
mutation createAuthor {
createAuthor(input: {
id: 123
firstName: "Bob"
lastName: "Smith"
}) {
id
firstName
lastName
}
}
query listAuthors {
listAuthors {
items {
id
firstName
lastName
}
}
}
mutation createPost {
createPost(input: {
id: 12345
title: "Title"
votes: 345
author: {
lastName: {
contains: "Bob"
}
}
}) {
id
title
votes
author {
id
firstName
lastName
}
}
}
对此的任何帮助将不胜感激。我的目标是查询作者并返回与该作者关联的所有帖子,并创建一个将帖子添加到作者的帖子突变。
【问题讨论】:
标签: graphql aws-appsync