angular - Apollo:将查询中的某些过滤器的数据视为陈旧真实

标签 angular graphql apollo apollo-client

我在这里面临一个非常奇怪的问题。

我们有一个 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 field picture, 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/

相关文章:

graphql - 使用 NEXT.js 和 Apollo 客户端 2 配置订阅

spring - 使用 Angular2 将文件上传到 REST API

angular - 如何运行 ng 相关命令作为其显示错误

python - Graphene-Django 嵌套过滤器(中继)

node.js - 使用 GraphQl : How to update fields using mutation 进行 Sequelize

graphql - 错误 : Invalid AST Node: {"input":"** } on graphql mutation (Amplify client)

javascript - 读取组件文件 Angular 中的响应 header

angular - 使用没有名称属性的 Angular ngmodel

javascript - GraphQL 使用字段值作为另一个查询的变量

GraphQL 突变为嵌套响应返回 null