首页 > 解决方案 > 我的突变适用于 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)
  )
}

在尝试找到解决方案几个小时后,我尝试替换ApolloAWS Amplify它并按预期工作。

问题是我不想使用AWS Amplify. 我不能使用 Fragments/offline/optimistic UI/fetchPolicy...我真的需要这些。

所以我想知道这是否应该是这样的,还是我在这里遗漏了什么?

标签: graphqlapolloapollo-clientaws-appsyncaws-amplify

解决方案


在Kamil Kisiela的帮助下,我们发现它在添加disableOffline: trueAWSAppSyncClient. 所以我寻找看起来像这样的错误并找到了这个。然后我升级 aws-appsync1.3.3并且它一直有效,即使没有disableOffline: true. 耶!


推荐阅读