【问题标题】:Error on GraphQL : no provided id but the store already contains an id ofGraphQL 上的错误:没有提供 id 但商店已经包含一个 id
【发布时间】:2018-08-10 14:33:21
【问题描述】:

我对 GraphQL 和 Apollo 非常陌生,我不明白下面的“aliasEmail”字段有什么问题。当我将此添加到查询中时,我收到此错误消息。当我从查询中删除它时,一切正常。 它在“types.graphql”中有很好的定义,只是一个简单的字符串字段。

index.js:2178 Unhandled (in react apollo:Apollo(withRouter(EmailSettingsContainer))) Error: Network 
error: Error writing result to store for query:
  query getCompanyForAliasEmailEditForm($companyId: ID) {
    Company(id: $companyId) {
      name
      isTaxActive
      telFixe
      aliasEmail
      telMobile
      __typename
    }
}

Store error: the application attempted to write an object with no 
provided id but the store already contains an id of 
Company:cje6xkcnxl83u01353a20p1t6 for this object. The selectionSet 
that was trying to be written is:
  Company(id: $companyId) {
    name
    isTaxActive
    telFixe
    aliasEmail
    telMobile
    __typename
  }

【问题讨论】:

    标签: graphql apollo


    【解决方案1】:

    听起来好像已经在应用程序的其他地方进行了另一个查询,该查询也返回 Company 对象,并且该查询包含 id(或 _id)字段,而本例中的查询不包含。 Apollo 使用 typename 和 id 来为您的查询结果生成缓存键(除非使用 dataIdFromObject 来修改此行为),因此在检测到上述差异时会引发错误。尝试在 getCompanyForAliasEmailEditForm 查询中包含 id 字段。

    【讨论】:

    • 谢谢丹尼尔。我将“id”添加到查询中的请求字段中,这解决了问题:-)
    猜你喜欢
    • 2017-06-16
    • 2021-07-06
    • 1970-01-01
    • 2018-04-19
    • 2020-08-24
    • 2019-05-29
    • 2012-01-27
    • 2018-12-06
    • 2017-10-06
    相关资源
    最近更新 更多