进行突变后,我要调用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())之后,我调用了getSiteList()方法来获取最新数据,但仍在获取旧数据。该如何解决?