简体   繁体   English

在第一个set上中继readyState ABORT

[英]Relay readyState ABORT on first setVariables

I have a Relay container that defines the following initialVariables and fragments: 我有一个Relay容器,它定义了以下initialVariables和片段:

  initialVariables: {
    enableExistingThreadQuery: false,
    recipientValue: null,
    contactId: null,
  },
  fragments: {
    viewer: () => Relay.QL`
      fragment on viewer {
        organization @include(if: $enableExistingThreadQuery) {
          existingThread (recipientValue: $recipientValue, contactId: $contactId) {
            id
          }
        }
      }
    `,
  }

So I need this query to run when I set recipientValue and contactId : 所以,我需要这个查询时,我设置recipientValue使用ContactID运行:

relay.setVariables({
  recipientValue: ...,
  contactId: ...,
  enableExistingThreadQuery: true,
}, readyState => {
  console.log(readyState);
});

The first time I set these variables, this successfully runs the query and we get the data on the frontend. 一次设置这些变量时,这将成功运行查询,并且我们在前端获取数据。 However, readyState only logs once with the following sequence of events: 但是, readyState仅使用以下事件序列记录一次:

  • NETWORK_QUERY_START NETWORK_QUERY_START
  • CACHE_RESTORE_START CACHE_RESTORE_START
  • ABORT 中止

With no errors, but done and ready are both false . 没有错误,但doneready都为false

The second time I make this call to relay.setVariables it loads the data from the cache and done and ready are both true . 第二次我对relay.setVariables进行调用时,它从缓存加载数据, doneready都是true

What might be causing setVariables to abort the first time it's called, even when the data is still successfully returned? 是什么导致setVariables在首次调用时中止,即使仍成功返回了数据也是如此?

In your browser's debugger, set a breakpoint on the following line in GraphQLQueryRunner.js (it should be near the end) to find out what is aborting your request: 在浏览器的调试器中,在GraphQLQueryRunner.js的以下行上设置一个断点(应该在结尾处),以找出导致请求中止的原因:

readyState.update({ aborted: true }, [{ type: 'ABORT' }]);

The most likely reason is that you have another setVariables / forceFetch call while the current query is not done. 最可能的原因是在当前查询未完成时,您还有另一个setVariables / forceFetch调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM