Ven*_*kat 6 apollo graphql angular
我正在使用 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),
Run Code Online (Sandbox Code Playgroud)
订阅的“数据”从突变返回响应,但有没有办法使用“queryAccounts”返回的数据,它也作为此突变的一部分运行?
在反应中似乎有一种方法可以做到这一点,但我没有成功在 Angular 中做类似的事情。
小智 2
你提到有很多方法可以在反应中做到这一点,但我认为这不是真的。
让我解释一下 Apollo 中突变是如何工作的。
apollo.mutate()带着refetchQueries选项运行console.log(data))refetchQueries都会启动一个新的 HTTP 请求并针对服务器运行。我在文档中对此进行了解释:https ://www.apollographql.com/docs/angular/features/cache-updates.html#after-mutations
基本上,refetchQueries 不是获取或访问数据。
| 归档时间: |
|
| 查看次数: |
2369 次 |
| 最近记录: |