graphql - 我的突变适用于 Amplify,但不适用于 Apollo。为什么?
问题描述
我正在AWS AppSync
使用Apollo
. 到目前为止,一切都很好,只是我刚刚意识到我所有的突变都不能正常工作:
在 devtool 中,我可以看到返回的数据如下:
{
"data": {
"getProduct": {
"productId": "xxxxxxxxxxxxxxxxxxx",
"title": "my title",
"slug": "my slug"
}
}
}
...但是当我尝试 console.log 这些相同的数据时,我得到空值。只有我的突变(查询工作正常)才能做到这一点。
{
"data": {
"getProduct": null
}
}
这是我正在做的事情:
addProduct(variables): Observable<Product> {
return this.apollo.mutate({
mutation: gql`
mutation addProduct($product: AddProductInput) {
addProduct(product: $product) {
productId
title
slug
}
}
`,
variables
}).pipe(
tap(console.log)
)
}
在尝试找到解决方案几个小时后,我尝试替换Apollo
为AWS Amplify
它并按预期工作。
问题是我不想使用AWS Amplify
. 我不能使用 Fragments/offline/optimistic UI/fetchPolicy...我真的需要这些。
所以我想知道这是否应该是这样的,还是我在这里遗漏了什么?
解决方案
在Kamil Kisiela的帮助下,我们发现它在添加disableOffline: true
到AWSAppSyncClient
. 所以我寻找看起来像这样的错误并找到了这个。然后我升级 aws-appsync
到1.3.3
并且它一直有效,即使没有disableOffline: true
. 耶!
推荐阅读
- svg - React Storybook 添加 Svg sprite
- javascript - 如何在javascript中选择div?
- sql - 从 SCN_TO_TIMESTAMP(ORA_ROWSCN) 中提取日期
- c# - 转换 XML
我有将 Json 作为输入参数的 Webservice SOAP 方法。
//For sample string jsonString = "[{"Year":"2020","UserId":"1","Comp":"20","DeptId":"32","CategoryId":"53","ItemId":"0"}]"; string[] processStrin
- git - 使用 ssh 查看我的 GitHub 组织中的存储库
- mysql - 使用 Node.js 并在 AWS lambda 中编写的关闭数据库连接(Mysql)的正确方法是什么
- c++ - C++ ADO Excel 记录删除
- google-apps-script - 如何使此函数在具有多个工作表 ID 的循环中运行?
- json - ansible 将 json 解析为 include_tasks 循环
- amazon-ec2 - 从 Azure Devops 部署到 VPN 后面的 AWS 机器