问题
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