graphql - Apollo Angular:突变后,调用watchQuery方法未获取最新数据
问题描述
在我进行突变后,我正在调用 watchQuery 方法来获取更新的行,但它仍在获取旧数据。
public saveSite() {
const _site = JSON.parse(JSON.stringify(this.siteForm.value));
this.apollo.mutate({
mutation: createSite,
variables: {
site_name: _site.name,
desc: _site.desc,
site_type_id: _site.sitetype
}
}).subscribe((dataVal) => {
this.loading = dataVal.loading;
this.errors = dataVal.errors;
this.getSiteList();
}, (error) => {
this.errors = error;
});
}
public getSiteList() {
this.loading = true;
this.querySubscription = this.apollo
.watchQuery({
query: gql`
{
cmp_site{
id
desc
site_name
site_type_id
sitetype{
id
name
}
}
}
`
})
.valueChanges.subscribe(result => {
const sitedata: any = result.data;
this.sites = sitedata.cmp_site;
this.loading = result.loading;
this.error = result.errors;
});
在调用了 mutation(saveSite()) 之后,我调用了 get getSiteList() 方法来获取最新数据,但它仍在获取旧数据。如何解决这个问题?
解决方案
推荐阅读
- sql - oracle数据库中的查询限制
- symfony - 如何查看密钥过滤器的值是否存在于树枝中?
- php - 使用来自服务器的信息加载图像
- ios - iOS:如何快速将 NSMutableDictionary 添加到 NSMutableArray 的特定索引中?
- typescript - 如何使用 Typescript 和 SapUI5 解决两个模块系统
- c# - 多维数组中具有负值的记分牌给出异常
- c# - List中元素之间的TimeSpan差异
- rascal - 如何从 Rascal 的项目外部导入?
- javascript - beforeShowDay 不工作
- c++ - 引用 std::cout 导致段错误