Reactjs/Apollo/AppSync突变触发两次 [英] Reactjs/Apollo/AppSync Mutation triggered twice

查看:112
本文介绍了Reactjs/Apollo/AppSync突变触发两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在React/Apollo/AppSync中遇到问题,突变触发两次(或多次).我有一个React应用,该应用的更新突变是由通常的UI按钮onClick触发的.

I'm having an issue with React/Apollo/AppSync with mutations triggering twice (or more). I have a React app that has an update mutation triggered by the usual UI button onClick.

<button className={`btn btn-sm`} onClick={(event) => { that.toggleSubscription(event, subscriptionid, serviceid, status); }}>
    <i className={`fas ${icon} fa-fw`} />
    {title}
</button>

toggleSubscription函数如下所示:

The toggleSubscription function looks like this:

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突变(尽管这似乎发生在所有突变中).这是在出口声明上:

And the graphql mutation in question (although this seems to happen on all mutations). This is on the export statement:

export default compose(
    graphql(
        MutationToggleSubscription,
        {
            props: ({ ownProps, mutate }) => ({
                toggleSubscription: (personid, serviceid) => mutate({
                    variables: { personid: personid, serviceid: serviceid }
                })
            }),
        }
    ),
...

显示同时调用多个GraphQL服务器 这些调用几乎是相同的,但是还有一些其他的堆栈跟踪调用: 这两个请求几乎相同.以红色突出显示的通话似乎是两者之间的区别

Shows multiple and simultaneous calls to the GraphQL server The calls are almost identical, but there are some additional stacktrace calls: The two requests are almost identical. The calls highlighted in Red seem to be the difference between the two

任何帮助将不胜感激!

推荐答案

您可以尝试提供一个optimisticResponse吗?

Can you try providing an optimisticResponse?

例如 AppSync客户端当前需要作为突变的一部分出现一个optimisticResponse

The AppSync client currently needs an optimisticResponse being present as part of the mutation

这篇关于Reactjs/Apollo/AppSync突变触发两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆