【发布时间】:2018-06-28 11:23:00
【问题描述】:
我遇到了 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 }
})
}),
}
),
...
Shows multiple and simultaneous calls to the GraphQL server 这些调用几乎相同,但还有一些额外的堆栈跟踪调用: The two requests are almost identical. The calls highlighted in Red seem to be the difference between the two
任何帮助将不胜感激!
【问题讨论】:
-
你能再试一次吗? AppSync JavaScript SDK 有一个更新,不再要求您使用乐观响应,这在当时可能就是发生这种情况的原因。如果您不需要离线功能,您现在也可以在构造函数中使用
disableOffline:true。更多信息在这里:docs.aws.amazon.com/appsync/latest/devguide/…
标签: reactjs graphql react-apollo apollo-client aws-appsync