Graphql 为什么片段数据被提取但不能通过中继变异访问

Graphql 为什么片段数据被提取但不能通过中继变异访问,graphql,relayjs,Graphql,Relayjs,我有一个变种(),我想在其中删除一个节点。当呈现相关组件()时,它依赖于post rowId(数据库中行的主键)和查看器id。将发送以下查询 query Queries { viewer { id, ...F1 } } fragment F0 on Viewer { id } fragment F1 on Viewer { id, ...F0 } 及 我得到的响应包括viewer.id和post.rowId。正如你在这里看到的 { "data": {

我有一个变种(),我想在其中删除一个节点。当呈现相关组件()时,它依赖于post rowId(数据库中行的主键)和查看器id。将发送以下查询

query Queries {
  viewer {
    id,
    ...F1
  }
}
fragment F0 on Viewer {
  id
}
fragment F1 on Viewer {
  id,
  ...F0
}

我得到的响应包括
viewer.id
post.rowId
。正如你在这里看到的

{
  "data": {
    "post": {
      "id": "cG9zdDo0",
      "headline": "You hit me with a cricket bat.",
      "body": "Hello.",
      "rowId": 4
    }
  }
}
在这里

{
  "data": {
    "viewer": {
      "id": "viewer"
    }
  }
}
但是,当我想将它们传递给
DeletePostMutation
时,就像这样
this.props.post.id
它们是
未定义的。当我检查
this.props.post
时,我得到以下信息


该错误表明传递到DeletePostMutation的道具不是中继获取的数据,并且查看,似乎您正在为帖子和查看器构建一个新对象,而不是发送中继获取的帖子和查看器

我看到你在这样做:

  handleDelete(event) {
    this.props.relay.commitUpdate(
      new DeletePostMutation({
        post: { rowId: this.props.post.rowId },
        viewer: { id: this.props.viewer.id },
      })
    )
  }
请尝试以下方法:

  handleDelete(event) {
    this.props.relay.commitUpdate(
      new DeletePostMutation({
        post: this.props.post,
        viewer: this.props.viewer,
      })
    )
  }

由于您已经在中继后容器中编写DeletePostMutation的GraphQL片段,因此在DeletePostMutation中,每个道具都应该具有可访问的片段中定义的字段。

错误表明传递给DeletePostMutation的道具不是中继获取的数据,看一下,您似乎正在为post查看器构建一个新对象,而不是发送中继获取的post和查看器

我看到你在这样做:

  handleDelete(event) {
    this.props.relay.commitUpdate(
      new DeletePostMutation({
        post: { rowId: this.props.post.rowId },
        viewer: { id: this.props.viewer.id },
      })
    )
  }
请尝试以下方法:

  handleDelete(event) {
    this.props.relay.commitUpdate(
      new DeletePostMutation({
        post: this.props.post,
        viewer: this.props.viewer,
      })
    )
  }

由于您已经在中继后容器中编写了DeletePostMutation的GraphQL片段,因此在DeletePostMutation中,每个道具都应该具有可访问片段中定义的字段。

@jose-r-cruz非常感谢。现在撞到我的头了。应该考虑一下@jose-r-cruz非常感谢。现在撞到我的头了。我应该考虑一下