【发布时间】:2018-12-03 10:27:20
【问题描述】:
假设我的数据结构如下:
house: {
id: Int,
address: String,
neighborhood (Foreign Key, Nullable): {
id: Int,
name: String,
city (Foreign Key, Nonnull): {
id: Int (Nonnull)
name: String
}
}
}
我正在构建以下查询:
{
homes {
house {
id
address
neighborhood {
id
name
city {
id
name
}
}
}
}
}
GraphQL(React Apollo 前端,Graphene + Django 后端)抱怨说,当我尝试此查询时,我试图为非 null city.id 返回 null。这特别发生在没有邻域(也没有城市)的房屋中,因此当它实际上不应该深入到数据结构中时,它会尝试将 city.id 返回为空,因为父邻域为空。
我试图在可用时获取有效的社区详细信息(包括城市),在不可用时获取null 社区。什么是合适的方法?
【问题讨论】:
标签: graphql react-apollo graphene-python