Angular 阿波罗角服务
我使用grapqhl codegen将我的查询转换为可注入服务,一切都像一个符咒一样工作,此外,我不能再更新eQuerys了,因为我只有服务,我不能将服务传递到updateQuerys数组中。我希望userGql服务重新蚀刻数据,而不是使用缓存:Angular 阿波罗角服务,angular,typescript,graphql,graphql-codegen,Angular,Typescript,Graphql,Graphql Codegen,我使用grapqhl codegen将我的查询转换为可注入服务,一切都像一个符咒一样工作,此外,我不能再更新eQuerys了,因为我只有服务,我不能将服务传递到updateQuerys数组中。我希望userGql服务重新蚀刻数据,而不是使用缓存: loginAttempt() { const data = this.loginForm.value; this.loginGql .mutate({ data }, {updateQueries: [CANT ADD SE
loginAttempt() {
const data = this.loginForm.value;
this.loginGql
.mutate({ data }, {updateQueries: [CANT ADD SERVICE HERE]})
.pipe(
pluck("data", "login"),
switchMap(async (token: string) => {
await this.storage.setToken(token);
return this.userGql.fetch().toPromise();
})
)
.subscribe((res) => console.log("res: ", res));
}```
如果希望在变异后重新提取查询,则需要使用
refetcquerys
UpdateSeries
用于手动更新缓存(也不推荐使用,请参见update
),因此它不会提供所需的内容
我知道至少有两种方法可以使用refetchquerys
一种是按查询名称,这将在监视相关查询时起作用:
this.loginGql
.mutate({ data }, { refetchQueries: ["UserQuery"] }) // <-- this
.pipe(
pluck("data", "login")
)
.subscribe((token: string) => {
this.storage.setToken(token);
// ... no need to manually fetch the query here
})
this.loginGql
.mutate({data},{refetchquerys:[“UserQuery”]})//{
this.storage.setToken(token);
//…无需在此处手动获取查询
})
另一个选项是引用服务文档。我相信这会迫使你提出质疑
this.loginGql
.mutate(
{
data
},
{
refetchQueries: {
query: this.faqQuestionsQuery.document // <-- this
}
}
)
.pipe(
pluck("data", "login")
)
.subscribe((token: string) => {
this.storage.setToken(token);
// ... no need to manually fetch the query here
})
this.loginGql
.变异(
{
数据
},
{
参考查询:{
查询:this.faqQuestionsQuery.document//{
this.storage.setToken(token);
//…无需在此处手动获取查询
})
不要忘记变量在这里也很重要