我在这里面临一个非常奇怪的问题。
我们有一个 graphql 搜索查询,它接受过滤器并为我们提供项目列表。
查询是这样的
allOpportunityV2(only: String, page: Int, per_page: Int, q: String,
with: String, sort: String, filters: OpportunityFilter): OpportunityList
OpportunityFilter 是一个具有过滤器选择的对象,例如
{
duration: RangeInput,
home_mcs: [Int],
programmes: [Int]
}
当我进行此查询时,对于某些过滤器组合,即使之前已查询过,阿波罗也在发出网络请求,并且我在网络选项卡中得到了正确的响应,但是在阿波罗的成功方法中,我没有得到正确的响应。
预期结果:
查询成功时得到正确的响应
实际结果:
{
data: undefined
loading: false
networkStatus: 7
stale: true
}
对于某些组合,它只是随机发生,并且很难准确重现。
最佳答案
如此处所述 https://github.com/apollographql/apollo-client/issues/3030#issuecomment-448472845
After several trails I figured data is always null whenever there are missing fields from the projected result. For instance, if we're supposed to query a user like:
user { uuid email picture }
and for some reason the server does not return fieldpicture
, then result will be:
{ data: null loading: false networkStatus: 7 stale: true }
I've also noticed we'll get a Missing field picture warning on the console.
In my particular case, my backend never serializes
null
values. Since user's picture and many other fields are optional (nullable), we constantly face this problem.
这几乎总是后端服务器的问题。即使任何特定字段的数据为空,您也必须仔细序列化响应中的所有内容。这为我们解决了问题。
关于angular - Apollo:将查询中的某些过滤器的数据视为陈旧真实,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55337645/