Apollo 客户端:网络错误 {“type":“WriteError"} [英] Apollo Client: Network Error {"type":"WriteError"}

查看:32
本文介绍了Apollo 客户端:网络错误 {“type":“WriteError"}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 apollo 查询出现 网络错误 {"type":"WriteError"}.查询在到达客户端时执行得很好.但是在他的商店里写它有问题.任何想法可能会出错?这是查询:

I am getting Network Error {"type":"WriteError"} on my apollo query. Query executes just fine as well as it arrives to the client. But there is issue writing it tot he store. Any ides what can be going wrong? This is the query:

fragment BpmnProcessInstanceItemTask on BpmnTaskInstance {
  id
  dateStarted
  dateFinished
  task {
    name
    __typename
  }
  performer {
    name
    __typename
  }
  performerRoles
  __typename
}

fragment BpmnProcessInstanceItem on BpmnProcessInstance {
  id
  status
  process {
    name
    description
    type
    __typename
  }
  owner {
    name
    __typename
  }
  tasks {
    ...BpmnProcessInstanceItemTask
    __typename
  }
  dateStarted
  dateFinished
  __typename
}

query BpmnProcessInstancesQuery($input: BpmnProcessInstancesInput!) {
  bpmnProcessInstancesQuery(input: $input) {
    ...BpmnProcessInstanceItem
    __typename
  }
}

"

推荐答案

我自己刚碰到这个,找到了解决方案 这里.这是因为查询正在加载没有 id(或 id)的数据,然后无法与缓存中的现有数据合并.

I just ran into this myself, and found the solution here. It's happening because the query is loading data without an id (or ids), which then can't be merged with the existing data in the cache.

以以下示例查询为例:

{
  viewer {
    id
    fullName
    groups {
      id
      name
    }
  }
}

返回的数据将存储在缓存中,查看者一个条目,每组一个条目:

The returned data will be stored in the cache with one entry for the viewer and one entry per group:

User:asidnajksduih6
Group:9p8h2uidbjqshd
Group:d9a78h92lnasax

如果后续查询如下所示:

If a subsequent query looked like:

{
  viewer {
    id
    fullName
    groups {
      name
    }
  }
}

可能会发生冲突,因为不清楚应该在缓存中更新哪些组(结果集将不包括组 ID).

There could be a conflict because it's unclear which groups should be updated in the cache (the result set will not include group ids).

解决方案似乎是尽可能在您的查询中始终使用 ID.这避免了合并问题,并提高了后续无关查询命中缓存的机会.

The solution appears to be to always use ids in your queries wherever possible. This avoids the merge issue and it improves the chances for subsequent unrelated queries to have a cache hit.

以上描述了原因和解决方案.此问题的可能症状包括:呈现陈旧数据,或即使结果在您的缓存中也不呈现数据.正如此处指出的那样,这些错误是默默发生的,但是可以通过Apollo chrome 扩展程序在查询"标签中.

The above describes a cause and a solution. Possible symptoms of this problem include: rendering stale data, or rendering no data even though the results are in your cache. As pointed out here, these errors happen silently, however they can be seen via the Apollo chrome extension in the "queries" tab.

这篇关于Apollo 客户端:网络错误 {“type":“WriteError"}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆