【问题标题】:Mutation not requesting for actively fetched container data in fatQuery on RANGE_ADD在 RANGE_ADD 上的 fatQuery 中,突变不请求主动获取的容器数据
【发布时间】:2017-10-30 05:37:15
【问题描述】:

我正在尝试使用现在称为 Relay Classic 的 RANGE_ADD 突变(这可能已通过 Modern 解决)。我得到了错误:

Warning: writeRelayUpdatePayload(): Expected response payload to include the newly created edge `newThingEdge` and its `node` field. Did you forget to update the `RANGE_ADD` mutation config?

所以,是的,有效负载没有发送超出预期响应形状中的 clientMutationId 的任何内容,因为请求突变不要求它。

根据@Joe Savona https://github.com/facebook/relay/issues/521 的说法,如果没有相交的容器请求此数据,则可能会发生这种情况。但这对我来说并不完全正确。我的Route 请求:

things: (Component) => Relay.QL`
    query {
      allThings(variable: $variable) {
        ${Component.getFragment('things')},
      }
    }
`,

当我的 fatQuery 请求时:

fragment on AddMockThing {
  allThings(variable: "${variable}", first: 100) {
    edges { 
      node {
        id,
      },
    },
  },
  newThingEdge
}

现在你可能会说这些不是同一个查询,因为getFatQuery 版本中有额外的first: 100,但如果我不使用它,我会收到错误:

Error: Error: You supplied the 'edges' field on a connection named 'allThings', but you did not supply an argument necessary to do so. Use either the 'find', 'first', or 'last' argument.

另一方面,如果我将 first: 100 添加到 Route 查询中,我会收到错误:Error: Invalid root field 'allThings'; Relay only supports root fields with zero or one argument.

卡在 fatQuery 和困难的地方之间。非常感谢您的帮助!

【问题讨论】:

    标签: relayjs


    【解决方案1】:

    您收到验证错误,因为 Relay 编译器正在寻找连接参数 (first: X)。您可以通过添加 @relay(pattern: true) 指令来禁用此特定验证。这将胖查询标记为要匹配的“模式”,而不是具体的东西。

    fragment on AddMockThing @relay(pattern: true) {
      allThings(variable: "${variable}") {
        edges { 
          node {
            id,
          },
        },
      },
      newThingEdge
    }
    

    更多信息在这里:https://stackoverflow.com/a/34112045/802047

    【讨论】:

    • 谢谢@steveluscher!在我跳回该代码以使用您的建议(并替换我的解决方法)之前还需要一段时间,所以现在只想承认它。
    猜你喜欢
    • 2016-04-08
    • 2017-06-27
    • 2018-02-24
    • 2016-05-18
    • 2021-04-15
    • 2017-09-02
    • 2018-03-22
    • 2022-01-26
    • 2017-06-13
    相关资源
    最近更新 更多