【问题标题】:Relay.js Error: repeat() argument must be greater than or equal to 0 and not be infinityRelay.js 错误:repeat() 参数必须大于或等于 0 且不是无穷大
【发布时间】:2016-08-25 04:50:21
【问题描述】:

不知道我在这里做错了什么。我的中继查询似乎组成正确(即我可以验证查询是否成功返回预期的结果)但是当应用程序在浏览器中呈现时我收到Error: repeat() argument must be greater than or equal to 0 and not be infinity 的错误。

应用程序一直很好,直到我添加了分页结果的片段 (edge + node):

const ConversationContainer = Relay.createContainer(Conversation, {
  fragments: {
    conversation: () => Relay.QL`fragment on Conversation {
      id
      fingerprint
      unreadCount
      messages(first: 3) {
        pageInfo {
          hasNextPage
        }
        edges {
          node {
            body
          },
          cursor
        },
      }
    }`
  }
})

和演示组件:

class Conversation extends Component {
  render() {
    const { id, fingerprint, unreadCount, messages } = this.props.conversation;
    return <div>
      <div>conversation <code>{id}</code></div>
      <div>fingerprint: <code>{fingerprint}</code>, unreadCount: {unreadCount}</div>
      <pre>{JSON.stringify(messages, null, 2)}</pre>
    </div>;
  }
}

那么错误的原因是什么?

编辑:错误出现在 UI 中,由我的根组件的 renderFailure 属性呈现(也作为控制台中的警告)

const root = <Relay.RootContainer
  Component={AppContainer}
  route={new AppRoute()}
  renderLoading={() => <div>Loading...</div>}
  renderFailure={(error, retry) => <div>Error: {error.message}</div>}
/>;

【问题讨论】:

  • 中继片段对我来说看起来不错。问题可能与字符串有关:github.com/WebKit/webkit/commit/… 可能是打印messages 的元素一个一个会揭示一些东西。

标签: reactjs graphql relayjs


【解决方案1】:

我能想到的两件事:

中继网络层

这可能与您的 GraphQL 服务器有关,而不是中继。

看看 Relay 源代码中的这一行: https://github.com/facebook/relay/blob/a1a4d99cb698e1eed63d28f8291ef114115d515d/src/network-layer/default/RelayDefaultNetworkLayer.js#L193

我知道这很奇怪,但是您的服务器是否会返回带有负列值的错误?

getBabelRelayPlugin

https://github.com/facebook/relay/blob/00de34d32d51ba9e4d17e45280ad6d7e2734c6ed/scripts/babel-relay-plugin/src/getBabelRelayPlugin.js#L155

再次与错误有关,但这次是客户端架构验证。尽管您似乎说您的查询运行良好,但这意味着您的架构是有效的。

你能告诉我们 GraphQL 服务器返回什么吗?

【讨论】:

  • 很好的调用来查看负载中的错误。我在返回的有效负载 "Field 'id': No source non-global ID value could be fetched from the source object" 中看到错误,但没有负偏移(所有偏移 0
  • @craigb 我相信这是 Relay 中的一个错误,您的列可能为 0,并且偏移量计算为 column - 1,这打破了 repeat。我在这里开了一个PR:github.com/facebook/relay/pull/1105
猜你喜欢
  • 2013-05-27
  • 2011-11-20
  • 2011-12-19
  • 2011-04-18
  • 2012-04-07
  • 2016-07-03
  • 2023-04-11
  • 2016-04-01
相关资源
最近更新 更多