我遇到了 React/Apollo/AppSync 的问题,突变触发了两次(或多次)。我有一个 React 应用程序,它有一个由通常的 UI 按钮 onClick 触发的更新突变。
<button className={`btn btn-sm`} onClick={(event) => { that.toggleSubscription(event, subscriptionid, serviceid, status); }}>
<i className={`fas ${icon} fa-fw`} />
{title}
</button>
toggleSubscription 函数如下所示:
toggleSubscription = async (event, subscriptionid, serviceid, currentStatus) => {
event.preventDefault();
event.stopPropagation();
if (currentStatus === "mandatory") return;
console.log(serviceid);
await this.props.toggleSubscription(this.props.match.params.id, serviceid);
}
以及所讨论的 graphql 突变(尽管这似乎发生在所有突变上)。这是出口声明上的:
export default compose(
graphql(
MutationToggleSubscription,
{
props: ({ ownProps, mutate }) => ({
toggleSubscription: (personid, serviceid) => mutate({
variables: { personid: personid, serviceid: serviceid }
})
}),
}
),
...
显示对 GraphQL 服务器的多个并发调用 https://i.stack.imgur.com/Gk00o.png电话是almost相同,但有一些额外的堆栈跟踪调用:这两个请求几乎相同。以红色突出显示的调用似乎是两者之间的区别 https://i.stack.imgur.com/twB8s.png
任何帮助将不胜感激!