Angular Apollo在突变中使用来自重新获取查询的响应

前端之家收集整理的这篇文章主要介绍了Angular Apollo在突变中使用来自重新获取查询的响应前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用Apollo和GraphQL开发一个Angular项目.我有一个突变,用于更新与其相关的相关详细信息的帐户列表.成功变异后,我使用refetchqueries来查询API以获取更新的帐户列表.一切都有效,直到这一部分.

this.apollo.mutate({
        mutation: mutationCreateNewAccount,variables: {
            accountNumber: this.accountNumber,accountType: this.accountType,routingNumber: this.routingNumber,nameOfAcountHolder: this.name
        },refetchQueries: [{
            query: queryAccounts,variables: { accountNumber: this.accountNumber }
        }]}).subscribe(({ data }) => console.log(data),

订阅的“数据”返回来自变异的响应,但有没有办法可以使用’queryAccounts’返回的数据,这也是此突变的一部分?

似乎有一种方法可以做出反应,但我没有成功在Angular中做类似的事情.

解决方法

您可以拥有一个在重新获取时始终更新的watchQuery

this.apollo.watchQuery({
            query: query,variables: variables
        })
        .valueChanges
        .pipe(
            map(res => res.data)
        )
        .subscribe(data => {
            //Updated your data here
        },err => {

        })
       })

猜你在找的Angularjs相关文章