Relay ConnectionHandler.getConnectionID()连接不存在错误

问题描述 投票:0回答:2

我正在尝试清理我的应用程序中的中继 graphql 流。 Atm 在某些地方我仍在使用 fetchKey 和记录失效,我想将其更改为 @appendEdge/@appendNode 指令。不幸的是,每次我尝试获得要使用它们的正确连接时,都会出现警告:

Warning: [Relay][Mutation] The connection with id 'client:ParentType14nif3uirdfut431431hg2rr:__ParentTypeChildrenList_children_connection' doesn't exist. 

我正在使用

ConnectionHandler.getConnectionID(<id of the parent object of the fragment>, <connection key I've specified>)

有谁知道这里可能有什么问题吗?另外,如果我理解正确并且有效的话,我的边缘应该被添加到商店中,并且中继只会确定所有内容是否都是最新的,而不从服务器获取新的边缘,对吗?

graphql relayjs relaymodern react-relay
2个回答
1
投票

Relay 不仅通过父 ID 和连接密钥来匹配连接标识,还使用调用连接时使用的最新参数(“过滤器”)。 通过将

filters: []
传递给连接,您将告诉中继不应使用任何参数来确定连接身份。这有时可以工作,但如果您的参数实际上影响连接的输出,这可能会引入一些意外的行为,例如当仅某些参数发生更改时,您的连接结果不会更新。 或者,您可以将您调用连接的最新参数传递给您的
getConnectionId
调用。有时这可能非常冗长且难以做到,但没有其他解决办法。

来自文档:https://relay.dev/docs/guided-tour/list-data/updating-connections/#connection-identity-with-filters


0
投票

获取连接 ID 的另一种方法是在响应数据中包含“__id”,例如:

const tagQuery = graphql`
  query TagQuery($TagsByKeyInput: TagsByKeyInput!) {
    tagsByKey(input: $TagsByKeyInput) @connection(key: "Component_tags") {
      __id
      edges{
        ...rest
      }
    }
  }
`;

返回数据中的__id为连接id。 希望这有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.