【问题标题】:My mutations works properly with Amplify but not with Apollo. Why?我的突变适用于 Amplify,但不适用于 Apollo。为什么?
【发布时间】:2019-03-08 20:55:55
【问题描述】:

我正在使用 AWS AppSyncApollo。到目前为止,一切都很好,只是我刚刚意识到我所有的突变都不能正常工作:

在开发工具中,我可以看到返回的数据如下:

{
  "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...我真的需要这些。

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

【问题讨论】:

    标签: graphql apollo apollo-client aws-appsync aws-amplify


    【解决方案1】:

    Kamil Kisiela 的帮助下,我们发现将disableOffline: true 添加到AWSAppSyncClient 时再次起作用。 所以我寻找看起来像这样的错误,我找到了this。 然后我将aws-appsync 升级到1.3.3,它一直有效,即使没有disableOffline: true。耶!

    【讨论】:

      猜你喜欢
      • 2021-02-17
      • 1970-01-01
      • 2012-12-23
      • 2017-05-08
      • 1970-01-01
      • 1970-01-01
      • 2019-09-23
      • 2022-01-18
      • 2021-06-18
      相关资源
      最近更新 更多