在GraphQL中传递变量
我正在尝试在AWS AppSync控制台中运行GraphQL查询:在GraphQL中传递变量,graphql,aws-appsync,Graphql,Aws Appsync,我正在尝试在AWS AppSync控制台中运行GraphQL查询: query MyQuery { getUserInfoById(id: "1234566789") { account { id // need this value for getAvailableCourses } } getAvailableCourses(accountId: "", pageNumber: 0) { data {
query MyQuery {
getUserInfoById(id: "1234566789") {
account {
id // need this value for getAvailableCourses
}
}
getAvailableCourses(accountId: "", pageNumber: 0) {
data {
id
name
type
}
}
}
基本上,我需要
getUserInfoById
中的account.id
值,用于getAvailableCourses
。我显然是GraphQL新手。我该怎么做呢?据我所知,有两种方法可以做到这一点
id
并将其传递给另一个查询
AvailableCourses
连接冲突解决程序,并在冲突解决程序中使用$ctx.source.id
以获取更多详细信息。模式应该是这样的
type Account {
id : ID!
availableCourses: AvailableCourses
..
}
type AvailableCourses {
name: String!
type: String!
..
}
type Query {
getUserInfoById(id: ID!): Account
}
使用返回的字段作为数据源中第二个查询的输入正是字段解析器的用途。我不能肯定,因为我不知道您的模式或访问模式,但看起来您需要将可用课程设置为用户的子字段