仅从 getPendingTransactions 中看到 'COMMITTING' 而从未看到 'COMMIT_FAILED'?

Only seeing 'COMMITTING' from getPendingTransactions and never 'COMMIT_FAILED'?

我正在尝试对失败的突变设置重试,如 Relay 所记录:https://facebook.github.io/relay/docs/api-reference-relay-container.html#getpendingtransactions

我在 graphql 服务器上通过返回错误导致突变失败:

 mutateAndGetPayload: ({text}) => {
    return new Promise((resolve, reject) => {
      setTimeout(() => {
        resolve(new Error("failed"));
      }, 2 * 1000);
    });
  },

当我第一次执行突变时,我可以看到 'COMMITTING' 的状态。但是然后在下一个渲染 getPendingTransactions returns null 中,我无法弄清楚如何查看 'COMMIT_FAILED'.

的状态
var transactions = this.props.relay.getPendingTransactions(this.props.story);

console.log("TRANSACTIONS", transactions);

var transaction = transactions ? transactions[0] : null;

if (transaction) {
  console.log("STATUS", transaction.getStatus());
}

我一定是遗漏了一些东西,但到目前为止还想不通。

您与 COMMIT_FAILED 的交易不会在 pendingTransactions 中,因为它已经尝试过但已经失败。你在使用 RelayStore.update 进行变异吗?

您可以尝试使用 RelayStore.apply_update 创建交易。这个函数实际上是returns交易对象。然后您可以调用 transaction.commit()。如果失败,您的事务对象的状态应为 COMMIT_FAILED.