【问题标题】:What are the "GraphQL calls" in the `rangeBehaviors` attribute of the `RANGE_ADD` mutator config?`RANGE_ADD` mutator 配置的`rangeBehaviors` 属性中的“GraphQL 调用”是什么?
【发布时间】:2016-02-11 09:49:10
【问题描述】:

docs describerangeBehaviors 为:

GraphQL 调用映射到我们希望 Relay 在这些调用的影响下将新边添加到连接时表现出的行为。行为可以是“追加”、“前置”或“删除”之一。

文档中的示例是:

rangeBehaviors: {
  // When the ships connection is not under the influence
  // of any call, append the ship to the end of the connection
  '': 'append',
  // Prepend the ship, wherever the connection is sorted by age
  'orderby(newest)': 'prepend',
}

todos example repo 的另一个例子中,你有:

rangeBehaviors: {
  '': 'append',
  'status(any)': 'append',
  'status(active)': 'append',
  'status(completed)': null,
}

在这种情况下,什么是“GraphQL 调用”? “受到”这样一个电话的“影响”是什么意思?

【问题讨论】:

    标签: graphql relayjs


    【解决方案1】:

    当您在 Relay 中查询连接字段时,您可以指定参数,而不仅仅是 firstlastbeforeafter 的标准分页参数。

    在上面的 TodoMVC 示例中,我们通过当前过滤器的状态来限定查询。您显示的 TodoMVC 代码的含义是,对于过滤 "active""any" (或默认状态)状态的查询,突变应附加新的待办事项,但不适用于仅过滤到状态的查询"completed" (这在上下文中是有意义的,因为突变添加了一个新的、活跃的待办事项)。

    【讨论】:

    • 谢谢taion。因此,您是说突变配置实例将rangeBehaviors 对象中的键视为连接字段中存在的参数的参数名称/参数值组合?因此,假设一个名为todos 参数化的连接字段位于status 上(除了firstlast 等),rangeBehaviors 中名为status(any) 的键被mutator 解释为“如果@连接字段的987654335@参数值为any,行为应该是append"?
    • 这基本上是正确的——“调用”描述了所有字段参数的值(标准连接参数除外)。它必须是完全匹配的。如果没有匹配,那么 Relay 将重新获取整个连接。
    • 我们可能应该从文档中删除对“call”的引用。 “调用”是 GraphQL 原始 FB 内部版本中的一个概念(例如things.first(10).fizz(5));在开源版本中,这些成为字段参数(例如things(first: 10, fizz: 5))。
    猜你喜欢
    • 2016-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-10
    • 2016-09-17
    • 1970-01-01
    • 1970-01-01
    • 2016-04-03
    相关资源
    最近更新 更多