【问题标题】:How does fragment composition work in Relay?片段组合在 Relay 中是如何工作的?
【发布时间】:2016-06-02 18:35:56
【问题描述】:

让我们使用 TODO 示例。在TodoList它(第81行)有一个片段组成为

todos(status: $status, first: $limit) {
  edges {
    node {
      id,
      ${Todo.getFragment('todo')},
    },
  },
  ....
}

现在如果我添加一个循环

this.props.viewer.todos.edges.map(edge =>
console.log(edge.node.text)
);

在第 30 行调用 renderTodos(),它会输出 undefined

有趣的是,如果我们将 text 添加到片段中,如下所示

todos(status: $status, first: $limit) {
  edges {
    node {
      id,
      text,
      ${Todo.getFragment('todo')},
    },
  },
  ....
}

它实际上“声明”了两次文本(也在 Todo 组件中声明)并且循环完美运行。

我的问题是,为什么即使 Graphql 服务器返回的“属性”也无法从组合中取回?

【问题讨论】:

    标签: relayjs graphql graphql-js


    【解决方案1】:

    感谢 #relay 频道的 hueyp#7485。

    他指出这是有意设计的行为。

    https://facebook.github.io/relay/docs/thinking-in-relay.html#data-masking

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-20
      • 2016-05-06
      • 2017-04-30
      • 2017-11-08
      • 1970-01-01
      • 1970-01-01
      • 2018-05-07
      • 1970-01-01
      相关资源
      最近更新 更多