【发布时间】:2017-12-25 07:16:28
【问题描述】:
我有一个Relay 容器,它定义了以下初始变量和片段:
initialVariables: {
enableExistingThreadQuery: false,
recipientValue: null,
contactId: null,
},
fragments: {
viewer: () => Relay.QL`
fragment on viewer {
organization @include(if: $enableExistingThreadQuery) {
existingThread (recipientValue: $recipientValue, contactId: $contactId) {
id
}
}
}
`,
}
所以我需要在设置 recipientValue 和 contactId 时运行此查询:
relay.setVariables({
recipientValue: ...,
contactId: ...,
enableExistingThreadQuery: true,
}, readyState => {
console.log(readyState);
});
我第一次设置这些变量时,成功运行了查询,我们在前端获取了数据。但是,readyState 仅记录一次,并包含以下事件序列:
- NETWORK_QUERY_START
- CACHE_RESTORE_START
- 中止
没有错误,但done 和ready 都是false。
第二次我调用relay.setVariables 时,它会从缓存中加载数据,done 和ready 都是true。
什么可能导致 setVariables 在第一次调用时中止,即使数据仍然成功返回?
【问题讨论】:
标签: javascript reactjs graphql relay