Apollo Client: Network Error {“type”:“WriteError”}

给你一囗甜甜゛ 提交于 2020-01-24 22:42:09

问题


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
  }
}

"


回答1:


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.

Take the following example query:

{
  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
    }
  }
}

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).

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.

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.




回答2:


The BpmnProcessInstanceItemTask fragment if overlapping the existing tasks object through the __typename field. The same in this code:

query BpmnProcessInstancesQuery($input: BpmnProcessInstancesInput!) {
  bpmnProcessInstancesQuery(input: $input) {
    ...BpmnProcessInstanceItem
    __typename <-- *same field stored twice*
  }
}


来源:https://stackoverflow.com/questions/52773365/apollo-client-network-error-typewriteerror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!