问题描述
我正在使用 GraphQL 开发 AWS Amplify 应用程序。
假设我已经定义了以下祖父模型、父模型、子模型。
type Country
@model
{
id: ID!
name: String!
states: [State] @connection(keyName: "byCountry",fields: ["id"])
}
type State
@model
@key(name: "byCountry",fields: ["countryId","name"],queryField: "listStatesByCountry")
{
id: ID!
name: String!
countryId: ID!
country: Country @connection(fields: ["countryId"])
cities: [City] @connection(keyName: "byState",fields: ["id"])
}
type City
@model
@key(name: "byState",fields: ["stateId",queryField: "listCitysByState")
{
id: ID!
name: String!
stateId: ID!
state: State @connection(fields: ["stateId"])
}
根据上面的定义,我可以根据父元素列出子元素!例如,我有 listStatesByCountry
可以根据传递的国家/地区 ID 列出所有州。同样,我们可以使用 listCitysByState
查询根据所选州列出城市。
我的问题是:如何获取选定国家/地区的城市列表?虽然 City
和 Country
模型之间没有直接关系,但 State
模型位于它们之间!
我需要在 City
模型上定义类似以下内容,但我不知道 countryId
不存在于 City
模型中,因此必须从 {{ 1}} 属性!
state
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)