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

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

问题描述

我在阿波罗查询中得到了Network Error {"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)的数据,然后这些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

如果后续查询如下:

{
  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扩展名./p>

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客户端:网络错误{“类型":"WriteError"}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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