【问题标题】:Relay readyState ABORT on first setVariables在第一个 setVariables 上中继 readyState ABORT
【发布时间】: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
          }
        }
      }
    `,
  }

所以我需要在设置 recipientValuecontactId 时运行此查询:

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

第一次设置这些变量时,成功运行了查询,我们在前端获取了数据。但是,readyState 仅记录一次,并包含以下事件序列:

  • NETWORK_QUERY_START
  • CACHE_RESTORE_START
  • 中止

没有错误,但doneready 都是false

第二次我调用relay.setVariables 时,它会从缓存中加载数据,doneready 都是true

什么可能导致 setVariables 在第一次调用时中止,即使数据仍然成功返回?

【问题讨论】:

    标签: javascript reactjs graphql relay


    【解决方案1】:

    在浏览器的调试器中,在GraphQLQueryRunner.js 中的以下行设置断点(它应该接近结尾),以找出导致请求中止的原因:

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

    最可能的原因是您在当前查询未完成时有另一个setVariables/forceFetch 调用。

    【讨论】:

      猜你喜欢
      • 2021-08-30
      • 2016-11-19
      • 2017-01-11
      • 2016-12-17
      • 2017-04-04
      • 2015-12-05
      • 2014-07-21
      • 1970-01-01
      • 2014-10-29
      相关资源
      最近更新 更多